Menu

False-positive, uninitialized variable

Daniel
2022-09-20
2022-09-20
  • Daniel

    Daniel - 2022-09-20

    False-positive occurs when sizeof() is used in for loop to initialize a buffer.

    (warning) Uninitialized variable: buffer [uninitvar]

    unsigned8 buffer[8];
    unsigned32 u32, sum = 0;
    
    for(u32 = 0; u32 < sizeof(buffer); u32++) {
        buffer[u32] = u32;
    }
    
    for(u32=0; u32 < sizeof(buffer); u32++) {
        sum += buffer[u32];
    }
    
     
  • CHR

    CHR - 2022-09-20

    Thanks for reporting, I've added your example to this ticket: https://trac.cppcheck.net/ticket/11305

     
  • CHR

    CHR - 2022-09-20

    It's a different issue after all. The warning disappears if the type definition is visible. e.g. with typedef unsigned char unsigned8;.

     
  • Daniel

    Daniel - 2022-09-20

    Interesting. I included the header file that has the typedef. Is there any way to debug why the header information is not being loaded for the c file?

     
  • Daniel

    Daniel - 2022-09-20

    I included the header file with the -I and the problem is resolved. thanks.

     

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.