Menu

objectIndex false positive?

jacob s
2021-01-22
2021-01-23
  • jacob s

    jacob s - 2021-01-22

    hi,

    typedef struct {
        uint8_t padding[500];
    } struct_t;
    
    static struct_t s_zero = {0};
    
    void fun() {
        uint8_t *s_zero_bytes = (uint8_t*)&s_zero;
        for(int b=0; b<10; b++) {
            printf("%02x\n", s_zero_bytes[b]);
        }
    }
    

    will give these warnings:

    a.c:10:33: warning: The address of local variable 's_zero' might be accessed at non-zero index. [objectIndex]
            LOG("%02x", s_zero_bytes[b]);
                                    ^
    a.c:8:39: note: Address of variable taken here.
        uint8_t *s_zero_bytes = (uint8_t*)&s_zero;
                                          ^
    a.c:10:33: note: The address of local variable 's_zero' might be accessed at non-zero index.
            LOG("%02x", s_zero_bytes[b]);
    

    is this a false positive?

    thanks, jacob

     
  • Daniel Marjamäki

    Thanks! I agree it is a false positive. I created ticket https://trac.cppcheck.net/ticket/10133

     

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.