Skip to content

Commit

Permalink
Fix wrong handling of slash followed by id
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Aug 21, 2024
1 parent a0a6124 commit 88d7831
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/test/c/c51-reconst-bug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* A bug observed in the Linux reconstitution */

#define __MAP(v, from, to) \
(from < to ? (v & from) * (to/from) : (v & from) / (from/to))
int x;
6 changes: 4 additions & 2 deletions src/test/out/awk.c
Original file line number Diff line number Diff line change
Expand Up @@ -23524,7 +23524,8 @@ FID FOFFSET CODE
25 24101 (
25 24127 );\u0000a
25 24136 (
25 24140 /, &
25 24138 /
25 24140 , &
25 24144 );\u0000a
25 24150 =
25 24154 -
Expand Down Expand Up @@ -23710,7 +23711,8 @@ FID FOFFSET CODE
25 25920 (
25 25946 );\u0000a
25 25955 (
25 25961 /, &
25 25958 /
25 25961 , &
25 25965 );\u0000a
25 25972 =
25 25977 -
Expand Down
206 changes: 206 additions & 0 deletions src/test/out/c51-reconst-bug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
Table: Ids
EID NAME READONLY UNDEFMACRO MACRO MACROARG ORDINARY SUETAG SUMEMBER LABEL TYPEDEF ENUM YACC FUN CSCOPE LSCOPE UNUSED
91 MAXDIGIT 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
331 x 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0
441 main 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0
571 qqq 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1
589 __MAP 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
649 v 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
679 from 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
739 to 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
891 foo 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1
2975 __DATE__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
3295 __TIME__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
3575 __FILE__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
3865 __LINE__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
4055 __STDC__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
5355 _cscout_dummy1 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0
Table: Tokens
FID FOFFSET EID
2 297 2975
2 329 3295
2 357 3575
2 386 3865
2 405 4055
2 471 441
2 535 5355
2 558 5355
4 58 589
4 64 649
4 67 679
4 73 739
4 81 679
4 88 739
4 94 649
4 98 679
4 107 739
4 110 679
4 119 649
4 123 679
4 132 679
4 137 739
4 146 331
5 8 91
5 32 331
5 43 441
5 56 571
5 88 891
Table: Rest
FID FOFFSET CODE
2 287 \u0000a\u0000a#define
2 305
2 320 \u0000a#define
2 337
2 348 \u0000a#define
2 365
2 377 \u0000a#define
2 394 1\u0000a#define
2 413 1\u0000a\u0000a
2 466 \u0000aint
2 475 ();\u0000a
2 522 \u0000astatic void
2 549 (void) {
2 572 (); }\u0000a
3 152 \u0000a\u0000a\u0000a#pragma includepath
3 195 \u0000a
3 239 \u0000astatic void _cscout_dummy2(void) { _cscout_dummy2(); }\u0000a
4 48 \u0000a\u0000a#define
4 63 (
4 65 ,
4 71 ,
4 75 ) \\u0000a (
4 85 <
4 90 ? (
4 95 &
4 102 ) * (
4 109 /
4 114 ) : (
4 120 &
4 127 ) / (
4 136 /
4 139 ))\u0000aint
4 147 ;\u0000a
5 0 #define
5 16 11\u0000d\u0000aextern int
5 33 ;\u0000d\u0000aextern
5 47 ();\u0000d\u0000aint
5 59 ;\u0000d\u0000a\u0000d\u0000a
5 86 \u0000d\u0000a
5 91 () {\u0000d\u0000a
5 116 }\u0000d\u0000a\u0000d\u0000a
Table: Projects
PID NAME
16 unspecified
17 Prj1
18 Prj2
Table: IdProj
EID PID
331 17
441 17
589 17
649 17
679 17
739 17
2975 17
3295 17
3575 17
3865 17
4055 17
5355 17
91 18
331 18
441 18
571 18
589 18
649 18
679 18
739 18
891 18
2975 18
3295 18
3575 18
3865 18
4055 18
5355 18
Table: Files
FID NAME RO
2 host-defs.h 1
3 host-incs.h 1
4 c51-reconst-bug.c 0
5 prj2.c 0
Table: Filemetrics
FID PRECPP NCHAR NCCOMMENT NSPACE NLCOMMENT NBCOMMENT NLINE MAXLINELEN MAXSTMTLEN MAXSTMTNEST MAXBRACENEST MAXBRACKNEST BRACENEST BRACKNEST NULINE NPPDIRECTIVE NPPCOND NPPFMACRO NPPOMACRO NTOKEN NSTMT NOP NUOP NNCONST NCLIT NSTRING NPPCONCATOP NPPSTRINGOP NIF NELSE NSWITCH NCASE NDEFAULT NBREAK NFOR NWHILE NDO NCONTINUE NGOTO NRETURN NPID NFID NMID NID NUPID NUFID NUMID NUID NLABEL NMACROEXPANDTOKEN NCOPIES NINCFILE NPFUNCTION NFFUNCTION NPVAR NFVAR NAGGREGATE NAMEMBER NENUM NEMEMBER
2 0 NULL NULL NULL NULL NULL NULL NULL 16 0 1 1 NULL NULL NULL NULL NULL NULL NULL 18 2 0 0 0 0 0 NULL NULL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NULL 0 0 0 NULL 0 0 NULL NULL NULL 0 1 0 0 0 0 0 0
2 1 548 367 29 0 3 22 61 47 NULL 1 1 0 0 0 5 0 0 5 37 2 0 0 2 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 5 8 1 1 5 7 0 0 1 0 NULL NULL NULL NULL NULL NULL NULL NULL
3 0 NULL NULL NULL NULL NULL NULL NULL 15 0 1 1 NULL NULL NULL NULL NULL NULL NULL 0 1 0 0 0 0 0 NULL NULL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NULL 0 0 0 NULL 0 0 NULL NULL NULL 0 0 0 0 0 0 0 0
3 1 243 187 13 0 2 13 48 28 NULL 1 1 0 0 0 1 0 0 0 16 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 NULL NULL NULL NULL NULL NULL NULL NULL
4 0 NULL NULL NULL NULL NULL NULL NULL 4 0 0 0 NULL NULL NULL NULL NULL NULL NULL 4 1 0 0 0 0 0 NULL NULL 0 0 0 0 0 0 0 0 0 0 0 0 2 0 NULL 2 1 0 NULL 1 0 NULL NULL NULL 0 0 1 0 0 0 0 0
4 1 157 44 24 0 1 5 72 65 NULL 0 2 0 0 0 1 0 1 0 42 1 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 2 1 0 1 2 0 0 1 0 NULL NULL NULL NULL NULL NULL NULL NULL
5 0 NULL NULL NULL NULL NULL NULL NULL 8 0 1 1 NULL NULL NULL NULL NULL NULL NULL 18 3 0 0 0 0 0 NULL NULL 0 0 0 0 0 0 0 0 0 0 0 0 4 0 NULL 4 4 0 NULL 4 0 NULL NULL NULL 1 0 2 0 0 0 0 0
5 1 106 34 26 2 0 11 21 14 NULL 1 1 0 0 0 1 0 0 1 21 3 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 1 5 4 0 1 5 0 0 1 0 NULL NULL NULL NULL NULL NULL NULL NULL
Table: FileProj
FID PID
2 17
3 17
4 17
1 18
2 18
3 18
4 18
5 18
Table: Definers
PID CUID BASEFILEID DEFINERID
18 5 5 2
18 5 5 4
Table: Includers
PID CUID BASEFILEID INCLUDERID
17 2 2 1
17 4 3 1
17 4 4 1
18 2 2 1
18 2 2 1
18 4 3 1
18 4 4 1
18 5 3 1
18 5 5 1
Table: Providers
PID CUID PROVIDERID
17 2 2
17 4 4
18 2 2
18 2 2
18 4 4
18 5 5
Table: IncTriggers
PID CUID BASEFILEID DEFINERID FOFFSET LEN
18 5 5 2 471 4
18 5 5 4 146 1
Table: Functions
ID NAME ISMACRO DEFINED DECLARED FILESCOPED FID FOFFSET FANIN
589 __MAP 1 1 0 1 4 58 0
891 foo 0 1 1 0 5 88 0
4715 main 0 0 1 0 2 471 0
5355 _cscout_dummy1 0 1 1 1 2 535 1
Table: FunctionDefs
FUNCTIONID FIDBEGIN FOFFSETBEGIN FIDEND FOFFSETEND
589 4 76 4 142
891 5 95 5 117
5355 2 557 2 577
Table: FunctionMetrics
FUNCTIONID PRECPP NCHAR NCCOMMENT NSPACE NLCOMMENT NBCOMMENT NLINE MAXLINELEN MAXSTMTLEN MAXSTMTNEST MAXBRACENEST MAXBRACKNEST BRACENEST BRACKNEST NULINE NPPDIRECTIVE NPPCOND NPPFMACRO NPPOMACRO NTOKEN NSTMT NOP NUOP NNCONST NCLIT NSTRING NPPCONCATOP NPPSTRINGOP NIF NELSE NSWITCH NCASE NDEFAULT NBREAK NFOR NWHILE NDO NCONTINUE NGOTO NRETURN NPID NFID NMID NID NUPID NUFID NUMID NUID NLABEL NMACROEXPANDTOKEN NGNSOC NMPARAM NFPARAM NEPARAM FANIN FANOUT CCYCL1 CCYCL2 CCYCL3 CSTRUC CHAL IFLOW
589 0 NULL NULL NULL NULL NULL NULL NULL 0 0 0 0 NULL NULL NULL NULL NULL NULL NULL 0 0 0 0 0 0 0 NULL NULL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NULL 0 0 0 NULL 0 0 NULL 0 NULL 0 NULL 0 0 1 1 1 0.0 0.0 0.0
589 1 77 0 17 0 0 2 72 0 NULL 0 2 0 0 0 0 0 0 0 29 0 8 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NULL 3 NULL 0 0 0 1 2 2 0.0 18.5754 0.0
891 0 NULL NULL NULL NULL NULL NULL NULL 0 0 0 0 NULL NULL NULL NULL NULL NULL NULL 1 0 0 0 0 0 0 NULL NULL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NULL 0 0 0 NULL 0 0 NULL 16 NULL 0 NULL 0 0 1 1 1 0.0 0.0 0.0
891 1 23 15 4 1 0 2 18 0 NULL 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NULL 0 NULL 0 0 0 1 1 1 0.0 0.0 0.0
5355 0 NULL NULL NULL NULL NULL NULL NULL 5 0 0 1 NULL NULL NULL NULL NULL NULL NULL 5 1 0 0 0 0 0 NULL NULL 0 0 0 0 0 0 0 0 0 0 0 0 0 1 NULL 1 0 1 NULL 1 0 NULL 9 NULL 0 NULL 1 1 1 1 1 1.0 0.0 1.0
5355 1 22 0 3 0 0 1 21 5 NULL 0 1 0 0 0 0 0 0 0 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 NULL 0 NULL 0 1 1 1 1 1 1.0 0.0 1.0
Table: FunctionId
FUNCTIONID ORDINAL EID
589 0 589
891 0 891
4715 0 441
5355 0 5355
Table: Fcalls
SOURCEID DESTID
5355 5355
Done
12 changes: 9 additions & 3 deletions src/workdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ file_dump(Sql *db, ostream &of, Fileid fid)
break;
char c = (char)val;
Eclass *ec;

// Return to normal if slash didn't start a commend
if (cstate == s_saw_slash && c != '*' && c != '/') {
chunker.add('/');
cstate = s_normal;
}

if (cstate != s_block_comment &&
cstate != s_string &&
cstate != s_cpp_comment &&
Expand Down Expand Up @@ -338,9 +345,8 @@ file_dump(Sql *db, ostream &of, Fileid fid)
cstate = s_block_comment;
chunker.start("COMMENTS", table_is_enabled(t_comments), "/*");
} else {
chunker.add('/');
chunker.add(c);
cstate = s_normal;
// Should have set s_normal at the top
csassert(0);
}
break;
case s_cpp_comment: // Inside C++ comment
Expand Down

0 comments on commit 88d7831

Please sign in to comment.