#22 inverted database use causes invalid format error

closed-out-of-date
nobody
None
5
2011-07-03
2009-08-31
Gary
No

The following simple test case leads to an "File does not have expected format" error.
(This test case is pared down from code that appears in a Linux kernel variant.)

$ cat test.c
typedef void (*vfunc_ptr_t)(int);
void vfunc(int arg);

$ cscope -f t.out -q -u test.c

Find this C symbol: vfunc

There may be few compounding errors here:

1) vfunc appears to be parsed as a function call rather than a function defintion

2) when vfunc is located in the inverted database, putpostingref is called with a
p->fncoffset value of 0. The if-statement that handles that case will leave the
function name untouched:

if (p->fcnoffset == 0) {
if (p->type == FCNDEF) { /* need to find the function name */
if (dbseek(p->lineoffset) != -1) {
scanpast(FCNDEF);
fetch_string_from_dbase(function,
sizeof(function));
}
}
else if (p->type != FCNCALL) {
strcpy(function, global);
}
}

which will result in an empty function name (assuming the 'function' string value
starts out as all null characters).

3. This error is only detected in interactive mode. For example, this command line
version of the query quits quietly:

$ cscope -f t.out -d -L 0vfunc

without the inverted database it works:

$ cscope -f t.out -u -b test.c
$ cscope -f t.out -d -L0vfunc
test.c <global> 2 void vfunc(int arg);

4. Once this error is detected, and the error message is printed out on the top
line of the screen, it is awkward for the user to recover from the error. If the
user types <enter> a invalid command line argument is passed to the editor.
The user can then quit the editor and enter control-d, but control-c is ignored, and so
is <tab>. A suggestion: cscope should either just clear the screen, print the
error message and quit, or it should recover more gracefully.

A simple fix is to change "else if (p->type != FCNCALL)" into simply "else",
but this may just be a work-around rather than a fix.

Discussion

  • Gary
    Gary
    2009-08-31

    correction to point 3. There was a typo in my example. There should have been no space after the -L switch. This produces the same result as the interactive session:

    $ cscope -f t.out -d -L0vfunc
    File does not have expected format

     
    • status: open --> closed-out-of-date