Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#271 cscope builds bad database

Bill Lash

When trying to build a cscope database for the mame source code, the database would build but many searches would end with the error:

Internal error: cannot get source line from database

Since mame has a lot of c++ code, I tried to create a valid c file that would exhibit the same issue. I created a single line file, that while unorthodox, is, I believe valid c code. The file is:

int a(){b();}int b(){c();}

If you build cscope on this file, and do a search for ".*" you will get the above error message.

If you add a space between the first function definiton and the second (between the } and int) everything is ok.

Tracing things through the lexer, it seems that when the close } is detected, first and last are set equal, and yylex returns. The crossreference code stores the }, and then yylex is called again. The lex code then seems to match "int" as an identifier, and the code in fscanner.l sets ident_start to first. At this point first still is the index of the } in the my_yytext array, but yytext contains contains int.

I made a change in crossref.c so that when first=last, after the symbol is saved, it will increment first so that it is past the (in this case) }. This seems to fix this particular issue, however, I think there might be other problems.

1. I have not tested this with scanner.l so I don't know it it works for a non-flex build
2. I have concerns that there may be issues in other cases where the code in the findident label is executed, since it only goes back to a space or tab, so if other punctuation is before the identifier there may be issues

With this patch, I can build and search the database on the mame 0.145 source code.


  • Bill Lash
    Bill Lash