Menu

[patch] minor changes, cppcheck

2017-10-07
2017-10-07
  • Václav Haisman

    Václav Haisman - 2017-10-07

    Here is a patch that fixes some warnings discoreverd by cppcheck.

    diff -upd -r /home/wilx/bibutils_6.2.orig/lib/bibcore.c /home/wilx/bibutils_6.2/lib/bibcore.c
    --- /home/wilx/bibutils_6.2.orig/lib/bibcore.c  2017-08-10 03:02:30.000000000 +0200
    +++ /home/wilx/bibutils_6.2/lib/bibcore.c   2017-10-07 10:45:38.290638492 +0200
    @@ -984,7 +984,7 @@ bibl_write( bibl *b, FILE *fp, param *p
        if ( !b ) return BIBL_ERR_BADINPUT;
        if ( !p ) return BIBL_ERR_BADINPUT;
        if ( bibl_illegaloutmode( p->writeformat ) ) return BIBL_ERR_BADINPUT;
    -   if ( !fp && ( !p || !p->singlerefperfile ) ) return BIBL_ERR_BADINPUT;
    +   if ( !fp && !p->singlerefperfile ) return BIBL_ERR_BADINPUT;
    
        status = bibl_setwriteparams( &lp, p );
        if ( status!=BIBL_OK ) return status;
    diff -upd -r /home/wilx/bibutils_6.2.orig/lib/bibtexout.c /home/wilx/bibutils_6.2/lib/bibtexout.c
    --- /home/wilx/bibutils_6.2.orig/lib/bibtexout.c    2017-08-10 03:02:30.000000000 +0200
    +++ /home/wilx/bibutils_6.2/lib/bibtexout.c 2017-10-07 10:48:15.938803486 +0200
    @@ -462,14 +462,12 @@ out:
     static int
     append_title( fields *in, char *bibtag, int level, fields *out, int format_opts )
     {
    -   int title = -1,     short_title = -1;
    -   int subtitle = -1,  short_subtitle = -1;
        int use_title = -1, use_subtitle = -1;
    
    -   title          = fields_find( in, "TITLE",         level );
    -   short_title    = fields_find( in, "SHORTTITLE",    level );
    -   subtitle       = fields_find( in, "SUBTITLE",      level );
    -   short_subtitle = fields_find( in, "SHORTSUBTITLE", level );
    +   int title          = fields_find( in, "TITLE",         level );
    +   int short_title    = fields_find( in, "SHORTTITLE",    level );
    +   int subtitle       = fields_find( in, "SUBTITLE",      level );
    +   int short_subtitle = fields_find( in, "SHORTSUBTITLE", level );
    
        if ( title==-1 || ( ( format_opts & BIBL_FORMAT_BIBOUT_SHORTTITLE ) && level==1 ) ) {
            use_title    = short_title;
    diff -upd -r /home/wilx/bibutils_6.2.orig/lib/ebiin.c /home/wilx/bibutils_6.2/lib/ebiin.c
    --- /home/wilx/bibutils_6.2.orig/lib/ebiin.c    2017-08-10 03:02:30.000000000 +0200
    +++ /home/wilx/bibutils_6.2/lib/ebiin.c 2017-10-07 10:50:15.862921240 +0200
    @@ -376,7 +376,7 @@ ebiin_author( xml *node, str *name )
            p = xml_value( node );
            while ( p && *p ) {
                if ( name->len ) str_addchar( name, '|' );
    -           while ( *p && *p==' ' ) p++;
    +           while ( *p==' ' ) p++;
                while ( *p && *p!=' ' ) str_addchar( name, *p++ );
            }
        } else if ( xml_tagexact( node, "Initials" ) && !strchr( name->data, '|' ) ) {
    diff -upd -r /home/wilx/bibutils_6.2.orig/lib/iso639_2.c /home/wilx/bibutils_6.2/lib/iso639_2.c
    --- /home/wilx/bibutils_6.2.orig/lib/iso639_2.c 2017-08-10 03:02:30.000000000 +0200
    +++ /home/wilx/bibutils_6.2/lib/iso639_2.c  2017-10-07 10:53:09.730794390 +0200
    @@ -639,7 +639,7 @@ main( int argc, char *argv[] )
     {
        int ok;
        ok = check_alphabetical();
    -   return EXIT_SUCCESS;
    +   return ok ? EXIT_SUCCESS : EXIT_FAILURE;
     }
    
     #endif
    diff -upd -r /home/wilx/bibutils_6.2.orig/lib/medin.c /home/wilx/bibutils_6.2/lib/medin.c
    --- /home/wilx/bibutils_6.2.orig/lib/medin.c    2017-08-10 03:02:30.000000000 +0200
    +++ /home/wilx/bibutils_6.2/lib/medin.c 2017-10-07 10:54:33.722822121 +0200
    @@ -378,7 +378,7 @@ medin_author( xml *node, str *name )
            p = xml_value( node );
            while ( p && *p ) {
                if ( str_has_value( name ) ) str_addchar( name, '|' );
    -           while ( *p && *p==' ' ) p++;
    +           while ( *p==' ' ) p++;
                while ( *p && *p!=' ' ) str_addchar( name, *p++ );
            }
        } else if ( xml_tagexact( node, "Initials" ) && !strchr( name->data, '|' )) {
    
     
  • Václav Haisman

    Václav Haisman - 2017-10-08

    Here is one additional change. I think there is a missing return there:

    diff -upd -r ./bibutils_6.2.orig/lib/endxmlin.c ./bibutils_6.2/lib/endxmlin.c
    --- ./bibutils_6.2.orig/lib/endxmlin.c  2017-08-10 03:02:30.000000000 +0200
    +++ ./bibutils_6.2/lib/endxmlin.c   2017-10-08 16:12:09.581691375 +0200
    @@ -406,7 +406,7 @@ endxmlin_dates( xml *node, fields *info
                }
                if ( xml_tagexact( node->down, "pub-dates" ) ) {
                    status = endxmlin_pubdates( node->down, info );
    -               if ( status!=BIBL_OK );
    +               if ( status!=BIBL_OK ) return status;
                }
            }
        }
    
     
  • Chris Putnam

    Chris Putnam - 2017-10-14

    These are all good catches and will be fixed in the next release. And thanks for pointing me to cppcheck. I'm having fun generating library rules to check the calls for my core code.

     

Log in to post a comment.