Menu

undetected uninitialized variable

2015-08-24
2015-08-26
  • Dina Goldshtein

    Dina Goldshtein - 2015-08-24

    Today I found a very severe bug in our code where an uninitialized pointer was dereferenced. cppcheck (1.69) did not report the issue. After several tries I managed to reproduce it in a smaller environment:

    int do_something()
    {
        int* p;
    
        do
        {
            if (true) 
            {
            }
            else
            {
                return 1;
            }
    
            *p = 7;
    
            p = new int(9);
        } while (*p != 8);
    
        return 0;
    }
    
    int main(int argc, char* argv[])
    {
        return 0;
    }
    

    cppcheck's only output is "Memory leak: p" whereas dereferencing the uninitialized pointer is not mentioned.
    This is a minimal example, in the sense that if I remove one of the following, the error is indeed detected:

    • p = new int(9);
    • the if statement
    • The loop (i.e. keep just the body without the loop)
     
  • Daniel Marjamäki

    yes that should be reported. can you please report this to the issue tracker http://trac.cppcheck.net/ so we don't forget this.

     
    • Dina Goldshtein

      Dina Goldshtein - 2015-08-24

      I wanted to by my trac acount is not verified. I didn't get the mail verification e-mail.

       
  • Daniel Marjamäki

    ok sorry for the trouble. Sometimes the verification email does not work. I don't know why.

    Your verification code is 41mbnTVv

    please try to login. you should be asked for the verification code. and then it should work..

     
  • Dina Goldshtein

    Dina Goldshtein - 2015-08-26

    Opened the ticket. Thanks a lot!

     

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.