| 1 |
--- pscan-1.2.orig/scanner.l |
| 2 |
+++ pscan-1.2/scanner.l |
| 3 |
@@ -1,21 +1,31 @@ |
| 4 |
-%option yylineno |
| 5 |
|
| 6 |
%{ |
| 7 |
#include "pscan.h" |
| 8 |
static void skip_strings(char literal); |
| 9 |
+extern int cur_lineno; |
| 10 |
%} |
| 11 |
|
| 12 |
%x comment |
| 13 |
%x strings |
| 14 |
|
| 15 |
-reserved "default"|"struct"|"void"|"for"|"if"|"else"|"while"|"do"|"return"|"case"|"switch"|"break"|"auto"|"continue"|"goto"|"sizeof"|"static"|"typedef"|"union"|"volatile" |
| 16 |
+reserved "default"|"struct"|"void"|"for"|"if"|"else"|"while"|"do"|"return"|"case"|"switch"|"break"|"auto"|"continue"|"goto"|"sizeof"|"static"|"typedef"|"union"|"volatile"|"asm" |
| 17 |
|
| 18 |
vartype "char"|"double"|"enum"|"extern"|"float"|"int"|"long"|"register"|"short"|"signed"|"unsigned"|"const" |
| 19 |
|
| 20 |
-cprep "include"|"define"|"if"|"else"|"endif"|"ifdef"|"ifndef" |
| 21 |
+cprep "include"|"define"|"undef"|"if"|"else"|"elif"|"endif"|"ifdef"|"ifndef"|"error"|"line"|"pragma" |
| 22 |
+ |
| 23 |
|
| 24 |
%% |
| 25 |
-{reserved} state->last_token = NOT_PROBLEMATIC; |
| 26 |
+{reserved} {// Ignore reserved words because issue arises |
| 27 |
+ // if reserved sizeof used as argument to a defined |
| 28 |
+ // problematic function such as snprintf |
| 29 |
+ // but we also do not want to attempt to check these |
| 30 |
+ // for defined issues in setup_checks function as we know |
| 31 |
+ // they are undefined |
| 32 |
+ // Default last_token state is NOT_PROBLEMATIC |
| 33 |
+ |
| 34 |
+ // state->last_token = NOT_PROBLEMATIC; |
| 35 |
+ } |
| 36 |
|
| 37 |
{vartype} state->last_token = NOT_PROBLEMATIC; |
| 38 |
|
| 39 |
@@ -39,7 +49,8 @@ |
| 40 |
|
| 41 |
\' skip_strings('\''); |
| 42 |
|
| 43 |
-\/\/.*$ /* skip C++ style comments */ |
| 44 |
+ |
| 45 |
+\/\/[^\n]* /* skip C++ style comments */ |
| 46 |
|
| 47 |
[a-zA-Z_][_a-zA-Z0-9]* state = setup_checks(yytext, state); |
| 48 |
|
| 49 |
@@ -81,17 +92,15 @@ |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
- |
| 54 |
-"\n"|"\r" /* ignore LF's and CR's */ |
| 55 |
- |
| 56 |
- |
| 57 |
"/*" BEGIN(comment); |
| 58 |
|
| 59 |
<comment>[^*\n]* /* eat anything that's not a '*' */ |
| 60 |
<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ |
| 61 |
-<comment>\n /* do nothing */ |
| 62 |
+<comment>\n {cur_lineno++;} |
| 63 |
<comment>"*"+"/" BEGIN(INITIAL); |
| 64 |
|
| 65 |
+"\n" { cur_lineno++;} |
| 66 |
+ |
| 67 |
%% |
| 68 |
/********************************************************************** |
| 69 |
* pscan: http://www.striker.ottawa.on.ca/~aland/pscan/ |
| 70 |
@@ -118,24 +127,22 @@ |
| 71 |
/* static */ |
| 72 |
void skip_strings(char literal) |
| 73 |
{ |
| 74 |
- int c; |
| 75 |
+ int c,last_c=0,done=0; |
| 76 |
+ |
| 77 |
+ while (!done) |
| 78 |
+ { |
| 79 |
+ c=input(); |
| 80 |
+ |
| 81 |
+ if (c==EOF) |
| 82 |
+ return; |
| 83 |
+ |
| 84 |
+ if ((last_c!='\\') && (c==literal)) // non escaped literal found |
| 85 |
+ done=1; |
| 86 |
+ else if ((last_c=='\\') && (c=='\\')) // avoid \\ issue |
| 87 |
+ last_c=0; |
| 88 |
+ else |
| 89 |
+ last_c=c; |
| 90 |
+ } |
| 91 |
|
| 92 |
- while ((c = input()) != literal) |
| 93 |
- { |
| 94 |
- switch (c) { |
| 95 |
- |
| 96 |
- case '\\': |
| 97 |
- c = input(); |
| 98 |
- if (c == '\\') continue; |
| 99 |
- if (c == EOF) return; |
| 100 |
- if (c != literal) |
| 101 |
- unput(c); |
| 102 |
- break; |
| 103 |
- case EOF: |
| 104 |
- return; |
| 105 |
- |
| 106 |
- default: |
| 107 |
- break; |
| 108 |
- } |
| 109 |
- } |
| 110 |
+ return; |
| 111 |
} |