Menu

bibutils-4.15 bug report

dcb
2012-12-28
2013-01-02
  • dcb

    dcb - 2012-12-28

    Hello there,

    I just ran the static analyser cppcheck over the source code of
    bibutils-4.15. It said

    [modsout.c:300]: (error) Buffer is accessed out of bounds: pos
    [modsout.c:306]: (error) Buffer is accessed out of bounds: pos
    [modsout.c:312]: (error) Buffer is accessed out of bounds: pos

    The source code is

    int       i, found = -1, ntypes = 4;

    for ( i=0; i<ntypes; ++i ) {
            pos[i] = fields_find( f, src_names[i], level );

    but

    output_finddateissued( fields *f, int level, int pos[3] )

    Suggest code rework.

    Regards

    David Binderman

     
  • Chris Putnam

    Chris Putnam - 2013-01-02

    Thanks for the report. Actually the code is fine (if misleading) and cppcheck is
    confused.

    In the function definition, the "3" in the "int pos[3]" isn't actually used by the
    compiler (the only indices that are important are those before the last one in
    multidimensional arrays so the compiler can do the appropriate math to properly
    index the data). In this case, the function definition could also easily use
    "int pos[]" as well.

    In the calling function, the array passed is properly an integery array of size 4
    so there are no problems. (But clearly I forgot to update the "int pos[3]" in the
    function definition.)

    I will fix this up in 4.16 so that cppcheck will be happy.

    Chris.

     

Log in to post a comment.