This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MISRA false positive



Hi,

I'm using TI ARM compiler v5.1.7. And I think that following cases not violates MISRA rules. Or am I missing something?

Luděk Hezina

1. MISRA-C:2004 10.1/R

void a(uint32_t *b);
void c(void);

void a(uint32_t *b)
{
uint32_t e = *b;

*b = e + 1U;
}

void c(void)
{
uint32_t i = 0U;
a(&i); /* violates rule (MISRA-C:2004 10.1/R) The value of an expression of integer type shall not be implicitly converted to a different underlying type if the expression is not constant and is a function argument */
}

This is the same as SDSCM00050007 only different compiler.

2. MISRA-C:2004 12.9/R

double a(void);
double a(void)
{
double diff = 1.0;
diff = -1.0 * diff; /* violates rule (MISRA-C:2004 12.9/R) The unary minus operator shall not be applied to an expression whose underlying type is unsigned */
return diff;
}

Violates rule 12.9 even if uderlying type is double.

3. MISRA-C:2004 17.6/R

typedef struct _sA
{
double b;
}sA;

typedef struct _sB
{
double b;
}sB;

void c(sA *a, sB *b);

void c(sA *a, sB *b)
{
b->b = a->b; /* violates rule (MISRA-C:2004 17.6/R) The address of an object with automatic storage shall not be assigned to another object that may persist after the first object has ceased to exist ("a") */
}

Violates rule 17.6 even if scope of both parameters are equal.

4. MISRA-C:2004 12.2/R

#define ARRAY_LEN 10

typedef struct _sA
{
uint32_t array[ARRAY_LEN];
uint32_t index;
}sA;

void c(sA *a, uint32_t val);

void c(sA *a, uint32_t val)
{
a->array[a->index] = val; /* violates rule (MISRA-C:2004 12.2/R) The value of an expression shall be the same under any order of evaluation that the standard permits */
}

Violates rule 12.2 even if value of an expression if always the same.

  • Thank you for submitting concise test cases.  I can reproduce all of these problems.

    Luděk Hezina said:
    1. MISRA-C:2004 10.1/R

    As you noted, this is already recorded in SDOWP with id SDSCM00050007.

    Luděk Hezina said:
    2. MISRA-C:2004 12.9/R

    I filed SDSCM00050841 in the SDOWP system.

    Luděk Hezina said:
    3. MISRA-C:2004 17.6/R

    I filed SDSCM00050842 in the SDOWP system.

    Luděk Hezina said:
    4. MISRA-C:2004 12.2/R

    I filed SDSCM00050843 in the SDOWP system.

    Feel free to track any of these entries with the SDOWP link below in my signature.

    Thanks and regards,

    -George