Menu

uninitvar false positive

jacob s
2021-02-15
2021-02-15
  • jacob s

    jacob s - 2021-02-15

    hello,

    void fun()
    {
        struct a *vbuf = NULL;
        struct b *block;
    
        for (int i = 0; i < 2; i++) {
            vbuf = &video_buf[i];
            block = &video_block[i];
            break;
        }
    
        if (vbuf == NULL) {
            return;
        }
    
        block->data = 1;
    }
    

    gives:

    a.c:16:5: error: Uninitialized variable: block [uninitvar]
        block->data = 1;
        ^
    a.c:12:14: note: Assuming condition is false
        if (vbuf == NULL) {
                 ^
    a.c:16:5: note: Uninitialized variable: block
        block->data = 1;
        ^
    

    thanks, jacob

     
  • CHR

    CHR - 2021-02-15

    This reproduces for me with head. https://trac.cppcheck.net/ticket/9772 might be related.

     

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.