Search code examples
ccoverity

Why does coverity flag a warning for this?


I am not sure why the static code analysis tool Coverity flags:

CID 40172 (#1 of 1): Parse warning (PW.INCOMPATIBLE_PARAM)
1. incompatible_param: argument of type "volatile mpls_RuntimeInfo_t *" is incompatible with parameter of type "void *"

for this line:

memset(&SW_RuntimeInfo[idx],0,sizeof(mpls_RuntimeInfo_t));

when SW_RuntimeInfo is declared as volatile static mpls_RuntimeInfo_t SW_RuntimeInfo[LABEL_T_CNT] = { 0 }; in the global scope.
Why does it raise a flag & how do I fix this?


Solution

  • It's throwing the warning because you're passing a volatile pointer to a non-volatile parameter. If you really want to just make the warning go away, just cast your argument to void *. But perhaps you should re-visit whether your variable should be volatile, or initialize it in a different manner.