Menu

False positiv ignoredReturnValue ?

2021-10-06
2021-10-06
  • Enzo Marscheck

    Enzo Marscheck - 2021-10-06

    The following C code gives me the ignoredReturnValue warning for the strlen() call:

    #include <string.h>
    
    void Foo(SOME_SRUCT_TYPE_t *structVar)
    {
       if (strcmp(structVar->text, structVar->otherText) != 0)
       {
          structVar->len = (uint8_t)strlen(structVar->text);
          memcpy(structVar->otherText, structVar->text, (structVar->len + 1));
    
          if (structVar->len > MAX_LEN)
          {
             structVar->offset = 0;
          }
       }
    }
    

    this does not happen when I remove the casting for the strlen() return value.

    Sidenote: I would have used the issue tracer but i can't aply for an account since the server that is mentioned in the wiki seems to have a problem (see atachment)

     
  • CHR

    CHR - 2021-10-06

    Which version are you using? I do not get a warning with current head.

     
  • Enzo Marscheck

    Enzo Marscheck - 2021-10-06

    I am using the currently downloadable windows installer version 2.6 and the analysis is set to C99, forced C and Nativ. I have inconclusive errors activated but it is not marked as such.

     

    Last edit: Enzo Marscheck 2021-10-06
  • CHR

    CHR - 2021-10-06

    This is all I get (for any value of platform):

    > & 'C:\Program Files\Cppcheck\cppcheck.exe' --version
    Cppcheck 2.6
    > & 'C:\Program Files\Cppcheck\cppcheck.exe' --enable=all foo.c  --inconclusive --std=c99 --platform=unix32
    Checking foo.c ...
    foo.c:3:0: style: The function 'Foo' is never used. [unusedFunction]
    
    ^
    nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingIncludeSystem]
    

    Maybe the definition of SOME_SRUCT_TYPE_t needs to be visible?

     
  • Enzo Marscheck

    Enzo Marscheck - 2021-10-06

    Well I made a minimal example to illustrate that there is nothing special going on here and didn't want/can't paste the real code (specially not all of it) but It does the same when the result from strlen() gets written to a local or a global variable.

     

    Last edit: Enzo Marscheck 2021-10-06

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.