FreeRTOS Task creation

/*
 * Defines the prototype to which task functions must conform.  Defined in this
 * file to ensure the type is known before portable.h is included.
 */
typedef void (*TaskFunction_t)( void * );

so, the Form of a Task is:

void vTaskCode( void * pvParameters )

nothing else.

SonarLint gives a
Make the type of this parameter a pointer-to-const. The current type of pvParameter is void *.
Which is not helpful here.

Franz

Hello again @franz-ms-muc,

This is a false positive in the MISRA strict rule: it does not make an exception for functions passed as callbacks, as in your case.
I agree that if vTaskCode is passed as an argument that has a fixed type, such as TaskFunction_t, the rule must not raise an issue regarding its signature.

Just for the record, here is a minimal working example (really helpful for investigation):

typedef void (*TaskFunction_t)( void * );

void myTask(void *p) {
    (void)*p;
}

void bar(TaskFunction_t task);

void foo() {
    bar(&myTask);
}

Thank you for reporting this case. Unfortunately, we cannot change the strict MISRA rule because then it will no longer correspond to the MISRA standard. We can, however, implement a similar rule, that would correctly make an exception in the case you reported. I created a ticket for it, to be evaluated whether it is a reasonable thing to do.

BTW, your example helped me to spot another false positive with a similar problem: S5008. Fortunately, we are free to improve this rule as we wish, so here is the ticket.

Please let me know if you have further questions.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.