Menu

unreadVariable for array member

fenugrec
2022-06-17
2022-06-19
  • fenugrec

    fenugrec - 2022-06-17

    Hi,
    not sure if this is realistic to fix. Strictly speaking, the variable is used but only indirectly, via a struct that holds a pointer to the array.

    //cppcheck 2.8.
    //cppcheck test.c --enable=style
    // =>    style: Variable 'txdata[0]' is assigned a value that is never used. [unreadVariable]
    
    struct msg {
        char    *data;
    };
    
    //this next line is optional and changes nothing
    extern void sendstuff(struct msg *txmsg);
    
    void main(void) {
        struct msg txmsg;
        char txdata[2];
        txmsg.data = txdata;
    
        txdata[0]=0x55;
        //this next line is optional and changes nothing
        sendstuff(&txmsg);
    }
    
     
  • Daniel Marjamäki

    Thanks! I definitely consider this as a false positive we should fix.

    I have created ticket: https://trac.cppcheck.net/ticket/11139

     

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.