Menu

Invalid uninitStructMember warning due to parenthesis

NRK
2022-04-24
2022-04-25
  • NRK

    NRK - 2022-04-24

    Hi,

    Here's a sample code to reproduce the issue; this is especially annoying because the convention for C macros are to always wrap the argument in parenthesis.

    #include <stddef.h>
    
    struct Str { char *str; size_t len; };
    
    extern int
    main(void)
    {
        struct Str tmp;
        char *s;
    
        tmp.str = NULL;
        s = (tmp).str;
    
        return 0;
    }
    

    This produces the following error:

    Checking test2.c ...
    test2.c:11:7: error: Uninitialized struct member: tmp.len [uninitStructMember]
     s = (tmp).str;
          ^
    

    Tested on cppcheck v2.6.3

     

    Last edit: NRK 2022-04-24
  • CHR

    CHR - 2022-04-25

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11002

     

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.