--- pscan-1.2.orig/scanner.l +++ pscan-1.2/scanner.l @@ -1,21 +1,31 @@ -%option yylineno %{ #include "pscan.h" static void skip_strings(char literal); +extern int cur_lineno; %} %x comment %x strings -reserved "default"|"struct"|"void"|"for"|"if"|"else"|"while"|"do"|"return"|"case"|"switch"|"break"|"auto"|"continue"|"goto"|"sizeof"|"static"|"typedef"|"union"|"volatile" +reserved "default"|"struct"|"void"|"for"|"if"|"else"|"while"|"do"|"return"|"case"|"switch"|"break"|"auto"|"continue"|"goto"|"sizeof"|"static"|"typedef"|"union"|"volatile"|"asm" vartype "char"|"double"|"enum"|"extern"|"float"|"int"|"long"|"register"|"short"|"signed"|"unsigned"|"const" -cprep "include"|"define"|"if"|"else"|"endif"|"ifdef"|"ifndef" +cprep "include"|"define"|"undef"|"if"|"else"|"elif"|"endif"|"ifdef"|"ifndef"|"error"|"line"|"pragma" + %% -{reserved} state->last_token = NOT_PROBLEMATIC; +{reserved} {// Ignore reserved words because issue arises + // if reserved sizeof used as argument to a defined + // problematic function such as snprintf + // but we also do not want to attempt to check these + // for defined issues in setup_checks function as we know + // they are undefined + // Default last_token state is NOT_PROBLEMATIC + + // state->last_token = NOT_PROBLEMATIC; + } {vartype} state->last_token = NOT_PROBLEMATIC; @@ -39,7 +49,8 @@ \' skip_strings('\''); -\/\/.*$ /* skip C++ style comments */ + +\/\/[^\n]* /* skip C++ style comments */ [a-zA-Z_][_a-zA-Z0-9]* state = setup_checks(yytext, state); @@ -81,17 +92,15 @@ } } - -"\n"|"\r" /* ignore LF's and CR's */ - - "/*" BEGIN(comment); [^*\n]* /* eat anything that's not a '*' */ "*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ -\n /* do nothing */ +\n {cur_lineno++;} "*"+"/" BEGIN(INITIAL); +"\n" { cur_lineno++;} + %% /********************************************************************** * pscan: http://www.striker.ottawa.on.ca/~aland/pscan/ @@ -118,24 +127,22 @@ /* static */ void skip_strings(char literal) { - int c; + int c,last_c=0,done=0; + + while (!done) + { + c=input(); + + if (c==EOF) + return; + + if ((last_c!='\\') && (c==literal)) // non escaped literal found + done=1; + else if ((last_c=='\\') && (c=='\\')) // avoid \\ issue + last_c=0; + else + last_c=c; + } - while ((c = input()) != literal) - { - switch (c) { - - case '\\': - c = input(); - if (c == '\\') continue; - if (c == EOF) return; - if (c != literal) - unput(c); - break; - case EOF: - return; - - default: - break; - } - } + return; }