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.

Incorrect MISRA C:2004 10.1/R and 6.1/R Errors?

I am using CCS v5.1.0.08020 and MSP430 C compiler v4.0.0 with MISRA checks turned on.  I created a simple string length function that I want to use with literal strings ("example"), so I used a plain char argument.  I received a MISRA error on the indicated line for rule 10.1 (#1393-D (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 it is not a conversion to a wider integer type of the same signedness).

uint16_t MyStringLength1(const char string[])
{
    uint16_t i;

    i = 0u;
    while ((string[i] != '\0') &&           /* violates MISRA 10.1/R */
           (i < UART_MAX_STRING_LENGTH))
    {
        ++i;
    }
 
    return i;
}

It appears the compiler does not handle the types correctly when indexing into an array.  I feel I have seen this before. 

 

This led me to implement this version of the function:

uint16_t MyStringLength2(const char string[])
{
    char character;
    uint16_t i;

    i = 0u;
    character = string[i];                  /* violates MISRA 6.1/R */
    while ((character != '\0') &&           /* violates MISRA 6.1/R */
           (i < UART_MAX_STRING_LENGTH))
    {
        ++i;
        character = string[i];              /* violates MISRA 6.1/R */
    }
 
    return i;
}

I received a MISRA error on the indicated lines for rule 6.1 (#1484-D (MISRA-C:2004 6.1/R) The plain char type shall be used only for the storage and use of character values).  In my reading of rule 6.1, these statements should be valid.  Again, the compiler does not seem to handle the types correctly when indexing into an array.

Are these compiler errors?  Or do I not understand the MISRA rules correctly?

Thanks,

Austin

  • Austin,

    I submitted compiler bugs for these 2 cases. The Misra 10.1 error is bug # SDSCM00042327 and the Misra 6.1 error is SDSCM00042328. You can track the status of these bugs using the SDOWP link in my signature, where you will also see any updates made by the compiler team after they analyze the issues.