Menu

Couple of false positives with 1.79

Steve Hill
2017-07-11
2017-07-11
  • Steve Hill

    Steve Hill - 2017-07-11

    Hi,

    I've managed to isolate a couple of false positives that are issues in our codebase. It's not clear how I go about getting an account to create these directly so I thought that I would post here!

    FP 1

    void bar()
    {
       char aMixed[] = "aBcDeF";
       const char aUpper[] = "ABCDEF";
    
       ToUpper(aMixed);
    
       (void)memcmp(aMixed, aUpper, sizeof aUpper);
    }
    

    On the memcmp line, I get:

    Summary: Unnecessary comparison of static strings.
    Message: The compared strings, '"aBcDeF"' and '"ABCDEF"', are always unequal. Therefore the comparison is unnecessary and looks suspicious.

    However, the aMixed string is mutable and (in our application code) the function called does modify it so the memcmp is absolutely necessary.

    FP 2

    void bar()
    {
       baz *p;
       p = malloc(sizeof *p);
       free(p);
       p = malloc(sizeof *p);
       free(p);
    }
    

    On the second free statement, I get:

    Summary: Memory pointed to by 'p' is freed twice.
    Message: Memory pointed to by 'p' is freed twice.

    Note that this only appears to be a problem if the pointer is to a user-defined type.

    HTH,

    Steve.

     
  • Steve Hill

    Steve Hill - 2017-07-12

    Created tickets 8119 and 8120 for these FPs.

    S.

     

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.