Menu

False positive: Variable is assigned a value that is never used

raynebc
2019-09-03
2019-09-03
  • raynebc

    raynebc - 2019-09-03

    In Cppcheck 1.89, I'm seeing a new warning that the previous version didn't give. I was able to trigger this false positive with the following minimal code example:

    void function(int value)
    {
        static int array[16] = {0};
    
        if(value > 15)
            value = 15; //Bounds check
    
        if(array[value])
            puts("This element is already nonzero");
    
        array[value] = 1;
    }
    

    The warning would only be valid if it wasn't a static array.

     
  • Daniel Marjamäki

    Thanks! I agree it's a fp. I created this ticket: https://trac.cppcheck.net/ticket/9312

     

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.