Menu

cppcheck seems to fail on a gnulib #if directive

2019-02-13
2019-02-15
  • Tim Ruehsen

    Tim Ruehsen - 2019-02-13

    Hi,

    using cppcheck v1.86 (Debian unstable) gives me headaches with errors
    (and thus files beign skipped) with the attached file.

    It says (wrongly):
    The tested configurations have these preprocessor
    errors:\012HAVE_CONFIG_H=1 : [gl/c-ctype.h:78] #error "Only ASCII and
    EBCDIC are supported"

    See also: https://gitlab.com/gnutls/gnutls/issues/705

    Removing that part from the file and hard-coding C_CTYPE_ASCII works nicely.

    Maybe there is a known work-around !? If not and you consider this a
    bug, could someone file a bug in the issue tracker, please ?

    Thanks so much for cppcheck ! Tim

    BTW, the problematic part is

    if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \

    && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
    && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
    && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
    && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
    && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
    && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
    && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
    && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
    && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
    && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
    && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
    && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
    && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
    && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
    && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
    && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
    && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
    && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
    && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
    && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
    && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
    && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)
    

    / The character set is ASCII or one of its variants or extensions, not
    EBCDIC.
    Testing the value of '\n' and '\r' is not relevant.
    /

    define C_CTYPE_ASCII 1

    elif ! (' ' == '\x40' && '0' == '\xf0' \

         && 'A' == '\xc1' && 'J' == '\xd1' && 'S' == '\xe2' \
         && 'a' == '\x81' && 'j' == '\x91' && 's' == '\xa2')
    

    error "Only ASCII and EBCDIC are supported"

    endif

     
  • Daniel Marjamäki

    can you try to format it better. There is a button that looks like </> that you use for code.

     
  • Daniel Marjamäki

    when I check c-ctype.h I get no error. could you please try to create a small test case that reproduce the problem?

     
  • versat

    versat - 2019-02-15

    I downloaded gnutls-master.zip and copied the commands together to execute cppcheck manually:

    ../cppcheck --force -q -Ilib/include -Igl/ -Ilib/ -I. --error-exitcode=1 lib/ -i lib/unistring -i lib/minitasn1 --enable=warning --enable=style --enable=performance --enable=portability --std=c99 --suppressions-list=devel/cppcheck.suppressions --template='{id}:{file}:{line},{severity},{message}' --enable=information -v --output-file=cppcheck_lib_output.txt
    
    ../cppcheck --force -q -Ilib/include -Igl/ -Ilibdane/ -I. --error-exitcode=1 libdane/ --enable=warning --enable=style --enable=performance --enable=portability --std=c99 --suppressions-list=devel/cppcheck.suppressions --template='{id}:{file}:{line},{severity},{message}' --enable=information -v --output-file=cppcheck_libdane_output.txt
    

    I have only added the options at the end: --enable=information -v --output-file=cppcheck_lib_output.txt
    Neither with 1.86 nor with git head i was able to reproduce the issue.
    I have attached the output files.

    The only thing that does not look correct are these messages:

    ConfigurationNotChecked:lib/accelerated/aarch64/aarch64-common.c:119,information,Skipping configuration '__FILE__' since the value of '__FILE__' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    ConfigurationNotChecked:lib/accelerated/aarch64/aarch64-common.c:119,information,Skipping configuration '__FILE__;__LINE__' since the value of '__FILE__' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    

    I would expect Cppcheck to always define __FILE__ and __LINE__.
    But for code like this:

    #ifdef __FILE__
    #ifdef __LINE__
    #define gnutls_assert() _gnutls_assert_log( "ASSERT: %s[%s]:%d\n", __FILE__,__func__,__LINE__);
    #else
    #define gnutls_assert()
    #endif
    #else               /* __FILE__ not defined */
    #define gnutls_assert()
    #endif
    
    void f()
    {
        gnutls_assert();
    }
    

    Cppcheck (1.86 and head) outputs this:

    $ ./cppcheck --enable=information gnutls_assert.c
    Checking gnutls_assert.c ...
    [gnutls_assert.c:13]: (information) Skipping configuration '__FILE__' since the value of '__FILE__' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    Checking gnutls_assert.c: __FILE__...
    [gnutls_assert.c:13]: (information) Skipping configuration '__FILE__;__LINE__' since the value of '__FILE__' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    [gnutls_assert.c:13]: (information) Skipping configuration '__FILE__;__LINE__' since the value of '__LINE__' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    Checking gnutls_assert.c: __FILE__;__LINE__...
    

    Not sure if that is intended or useful.

    Btw.: I recommend to also use the option --library=gnu for gnutls. It defines such things like unlikely(), likely() and other GNU stuff.

     

    Last edit: versat 2019-02-15

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.