Menu

#69 fix errors reported by cppcheck

fixed
None
bug
5
2014-08-04
2014-04-24
dcb
No

[vars.c:1664]: (error) Dangerous usage of 'varname' (strncpy doesn't always null-terminate it).

(void) strncpy(varname, name, 128);
namelength = strlen(varname);

Maybe better code might be

strncpy(varname, name, 128);
varname[127] = '\0';
namelength = strlen(varname);

Discussion

  • Vasily Tarasov

    Vasily Tarasov - 2014-04-29

    Out of curiosity, what compiler do you use?

    In 1.5 branch the strncpy() code isn't in the var.c file anymore. But I want to check if we have any other places in the code where the same compilation error can occur.

    Thanks!

     
  • Vasily Tarasov

    Vasily Tarasov - 2014-07-31
    • status: open --> open-pending
    • Type: --> bug
     
  • Vasily Tarasov

    Vasily Tarasov - 2014-07-31
    • Status: open-pending --> pending
     
  • Vasily Tarasov

    Vasily Tarasov - 2014-07-31
    • status: pending --> stale
     
  • Vasily Tarasov

    Vasily Tarasov - 2014-07-31

    No reply from the user. Closing as "stale".

     
  • Vasily Tarasov

    Vasily Tarasov - 2014-08-01
    • status: stale --> pending
     
  • Vasily Tarasov

    Vasily Tarasov - 2014-08-01

    Got a reply from dcb via e-mail:

    "Not a compiler, but a static analysis checker called cppcheck, available from sourceforge."

    Reopening.

     
  • Vasily Tarasov

    Vasily Tarasov - 2014-08-02
    • summary: vars.c:1664: possible missing string terminator --> fix errors reported by cppcheck
    • status: pending --> accepted
    • assigned_to: Vasily Tarasov
     
  • Vasily Tarasov

    Vasily Tarasov - 2014-08-02

    The output of the latest cppcheck on the latest Filebench code (1.5):

    cvars/utils/mtwist/rdcctest.cc:210]: (error) Memory leak: params
    [cvars/utils/mtwist/rdtest.c:242]: (error) Memory leak: params
    [misc.c:128]: (error) Resource leak: cpuinfo
    [parser_gram.y:1667]: (error) Resource leak: f
    [parser_gram.y:3366]: (error) Memory leak: string
    [parser_gram.y:3593]: (error) Memory leak: fspathlist
    [parser_gram.y:3668]: (error) Memory leak: string
    [stats.c:185]: (error) Resource leak: statfd

    strncpy() problem is gone, but there are other issues.

     
  • Vasily Tarasov

    Vasily Tarasov - 2014-08-04
    • status: accepted --> fixed
     
  • Vasily Tarasov

    Vasily Tarasov - 2014-08-04

    Fixed with commit bb2d5d877676bf67870d6a1cbf56c0f921e3339a in Filebench-1.5 branch.

    Two errors reported in cvars/utils/mtwist/rdcctest.cc and cvars/utils/mtwist/rdtest.c are not actual errors. Moreover, Filebench does not run that code.