Potential False Positive with __attribute__ ((unused)) - c:S995

Running SonarQube with SonarScanner

We have multiple handler functions of type func(param1, __attribute__ ((unused)) param2) - some of them read param2, some modify its contents, others do not use it at all but they have the same prototype since they are expected to work in highly similar contexts. SonarQube raises issue S995 - Make the type of this parameter a pointer-to-const. - for the field that is marked as unused and does not appear in the function body - see the following example:

int S995_trigger(int a, __attribute__ ((unused)) char *b) {
        printf("S995 trigger %d\n", a);

will raise “Make the type of this parameter a pointer-to-const. The current type of “b” is “char *”.”

Is this the intended behavior of the rule? Since it was inspired by MISRA I assume the “unused” attribute wasn’t considered for these situations. Is there a different rule allowing us to obtain the same results but which considers the gcc attribute extensions?

Hello @Adrianh,

This is the intended behavior of the rule. We currently don’t have another rule that considers the attribute. Is there a reason why you don’t want to make the type const char * for the unused parameter? At the end S995_trigger should be able to accept an argument of type const char*.

If you have a specific reason why you don’t want to apply the rule in such a situation, you should just mark them as won’t fix.


1 Like

Thank you, we’ll likely mark as “won’t fix”. The reason for not marking const is that we have a large set of handler functions some of which might modify that parameter, others may not; we have ((unused)) for gcc-specific complaints and were looking into an option for SonarQube as well.