Menu

Writing a cppcheck rule for detecting hexadecimal escape sequences

2015-11-11
2015-11-13
  • orbitcowboy

    orbitcowboy - 2015-11-11

    I am trying to write a cppcheck rule that detects hexadecimal escape sequences in C/C++ code.

    Here is an example code (test.c):

    const char *c = "\x41g";
    

    I noticed that cppcheck already converts it into its correct character interpretation ("\x41g" is equal to "Ag"):

    $ cppcheck --rule=".+" test.c 
    Checking test.c...
    [test.c:1]: (style) found ' const char * c ; c = "Ag" ;'
    

    Is there any way to write a rule that checks the input file, before it is preprocessed by cppcheck?

    Many thanks

    Martin

     
  • Daniel Marjamäki

    I have not tried it.. but you should be able to use the "raw" tokenlist in the rule. Then your rule is executed before all the Tokenizer simplifications.
    This sounds like a useful rule so feel free to add it in the Cppcheck repo.
    Good luck!

     

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.