Menu

misra 12.2 false negative?

2021-01-04
2021-01-16
  • Richard Smith

    Richard Smith - 2021-01-04

    I discovered some expressions in our code earlier today that I expected to be triggering 12.2 but they don't seem to make it happen. I've duplicated on HEAD with the following small snipit.

    Can someone verify this is not working?

    m1.c is the following:

    unsigned char buff_8[2];
    
    uint32_t shift_u8t_8(void)
    {
        unsigned char u8_val = buff_8[0] << 8u;
    
        return (uint32_t)(buff_8[0] << 8u)
    }
    
    /home/src/cppcheck.git/addons/test$ 
    /home/src/cppcheck.git/addons/test$ ../../build/bin/cppcheck --addon=misra.py ./misra/m1.c
    Checking misra/m1.c ...
    /home/src/cppcheck.git/addons/test$ 
    
     
  • Jean-Loic MARTIN

    Hi Richard,

    You are right, this is not working for unsigned char array.
    This is ok for unsigned char and signed char.
    It should generates an error in your case (and in the case below).

    char cFunc(unsigned char ucVar)
    {
        unsigned char ucToto[2];
        ucToto[1] = ucVar;
        ucToto[0] = (unsigned char)(ucToto[1] << 8u);
        return ucToto[0];
    }
    

    I think the problem comes from array variables. But i'm not able to correct it i'm not a python programmer.

     

    Last edit: Jean-Loic MARTIN 2021-01-05
  • Jean-Loic MARTIN

    Up of this topic.
    Has someone opened a ticket for that problem ?

     
  • Daniel Marjamäki

    good that you reminded me. Now I have created a ticket:
    https://trac.cppcheck.net/ticket/10113

     
  • Jean-Loic MARTIN

    thank you Daniel !

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.