Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

C: return in macro doesn't seem to be considered

Hi,

I am running Parasoft for MISRA.

Following a simplified code example:

define RC(func) \

do { \
rc_t rc_ = func; \
if is_error(rc_) return rc_;
} while (0)

struct info_t {
rc_t (*handler)();
};

rc_t caller() {
struct info_t info = {0};
RC(called_function(&info));
// From this point, info is well initialized by the called function
return info.handler();
}

MISRA considers that handler may be NULL when invoked and reports DIR_4_1-b-2 issue. When looking at the scenario leading to this issue in the report, the called function returns an error, the RC macro returns this error as well but then MISRA assumes that the code continues to the handler invocation.

I tried to suppress this warning by adding a _Pragma in the macro itself without success.

What can I do?

Thanks

Tagged:

Answers

  • Bogdan Czwartkowski
    Bogdan Czwartkowski Posts: 163 admin

    @JackDanielZ ,
    We will need additional details to reproduce and explain why the violation was reported. Our support team will contact you directly regarding this.

Tagged