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 warning (MISRA-C:2004 17.6/R) Misreported - Additional Problem

Note that this is not the same problem as reported in my other post http://e2e.ti.com/support/development_tools/compiler/f/343/t/89533.aspx#310031 (SDSCM00037487)

CGT 5.0.1

(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

In the following code, the assignment of &myLocalStruct->data to myDataPtr in myFunc has MISRA 17.6 reported. myDataPtr only persists for the duration of the function, and therefore does not persist longer than data passed into that function.

typedef struct
{
    uint8 data;
} Struct_T;

void myFunc(Struct_T *myLocalStruct);
void main(void);

void myFunc(Struct_T *myLocalStruct)
{
    uint8 *myDataPtr;

    myDataPtr = &myLocalStruct->data; /* (MISRA-C:2004 17.6/R) reported here
}

void main(void)
{
    Struct_T myStruct = { 0U };

    myFunc(&myStruct);
}

As an aside, I note that the following SDOWP reports on MISRA warnings have not been fixed in CGT 5.0.1 although they are reported as being fixed in older CGT releases 4.9 and 4.10. Please can you advise whether these will be addressed in CGT 5.x stream.

SDSCM00039420 Compiler issues unwarranted warning for violation of Misra 9.2 for zero initialization of multi dimensional arrays
SDSCM00038580 Incorrect violation of rule MISRA-C rule 6.1 is reported by the compiler

Regards, Tony

  • Tony,

    I submitted SDSCM00045452 to track this new issue in CGT 5.0.1.

    Regarding the older bug reports 39420 and 38580 those should be fixed in CGT 5.0.x as well. Do you find that they are not?

  • Hi Aarti,

    I think they are not fixed, but I will double check tomorrow to confirm.

    Regards, Tony.

  • Hi Aarti,

    I still get MISRA 9.2 warnings on the zero initialisation of structures, so the following for example:

    IdVersionFirmwareIssue_T sctFirmwareIssue_M = { 0U };

    #define PTR_COM_NULL_SIG_CALLBACK_C ( (void (*)(ComSignalId_T const enumSigId)) 0 )
    static ComFnCallbackPtr_T fnComCallbackPtr_M[NUM_COM_SIGNALS_E] = {PTR_COM_NULL_SIG_CALLBACK_C};

    I still get MISRA 6.1 reported when using character values, so between pragmas in the following for example (but not within the while statement!):

    typedef unsigned char uint8; /**< 8 bit unsigned integer */

    uint32 Util_ChrToInt(
        uint8 const chrPtr[]) /**< Pointer to string */
    {
        uint8_least nIndex = 0U;
        uint32 nInteger = 0U;
        uint32 nTempUnit32;

        while ( (chrPtr[nIndex] != 0U)
               && (nIndex < N_MAX_STRING_LENGTH_C)
              )
        {
    #pragma CHECK_MISRA("-6.1") /* (MISRA-C:2004 6.1/R) The plain char type shall be used only for the storage and use of character values (SDSCM00038580) */

            if ((chrPtr[nIndex] >= '0') && (chrPtr[nIndex] <= '9'))

    #pragma RESET_MISRA("6.1") /* Restore MISRA default setting for this rule */
            {
                nTempUnit32 = (uint32)chrPtr[nIndex] - (uint32)'0';
                nInteger = (nInteger * 10U) + nTempUnit32;
            }
            else
            {
                /* Invalid string */
                Index = N_MAX_STRING_LENGTH_C;
                nInteger = 0U;
            }

            nIndex++;
        }

        return (nInteger);
    }

    Regards, Tony.

  • Tony,

    For the MISRA 9.2 warning, can you send a complete compilable source file to reproduce? I made up a definition for the structure since it was not provided in the snippet, but can't get the warning to appear.

    For the MISRA 6.1 warning, it looks to be related to bug # SDSCM00042328, which was fixed recently, so I expect the fix will appear in the next release of the ARM CGT.

  • Hi Aarti,

    I know the following is not a complete file, but it should be sufficient to reproduce the MISRA 9.2 warning I get. It is a simpler example than my original:

    typedef struct
    {
    unsigned char nModuleId;
    unsigned char nInstanceId;
    unsigned char nApiId;
    unsigned char nErrorId;
    } DetLog_T;

    DetLog_T sctDetLog_M[0x100U] = { 0U };

    Regards, Tony.

  • Tony,

    Thank you for the test case. I can reproduce it so it looks like there is still an issue with CGT 5.0.x. I have submitted a new bug report to track this - SDSCM00045473.