Camm Maguire <c...@maguirefamily.org> writes:

> =============================================================================
> Subject: Bug#667443: cxref dumps core with function def with function pointer
> Reply-To: John Vogel <jvog...@stny.rr.com>, 667...@bugs.debian.org

...

> When cxref encounters a function definition that contains a pointer to 
> function
> in the arguments, it segfaults. I have included a smal test file that
> demonstrates what I'm seeing. The command line I'm using to reproduce this is:
>
> cxref -xref -CPP "-E -CC -dD -dI" cxref-bomb.c
>
> Trying to use cxref-cpp prevents the segfault, but output is empty except for
> the default header from cxref. Switching the comment from the int 
> (*f)(int,int)
> to the int f is enough to get cxref through without segfaulting.
>
> I've spent some time trying to get a handle on the fault, but I seems to lead
> to the lexer or more likely the parser. If I get some time I'll try to dig
> deeper on this. Maybe later this month.

The code causing the problem is:

-------------------- cxref-bomb.c --------------------
int
f3 (a, b, f)
    int a, b;
    int (*f)(int, int);
/*    int f;*/
{
    return f(a, b);
}
-------------------- cxref-bomb.c --------------------

This is a known bug in cxref (since about 6 months ago) and not one
that I plan to fix.

The bug reporter is correct, this is a bug and part of the valid C
language syntax that is not handled correctly.  The code that needs to
be fixed is in the parser (not the lexer) but it is in the middle of
the code for handling function definitions that gets confused by
seeing a second function definition.  I tried looking for a fix when
the bug was originally reported to me, but it was difficult because
this part of the code is quite fragile.

The reason that I don't plan to fix the problem is that this old style
code has been deprecated for about 20 years, the bug has been reported
only recently, the code is fragile in this area (hence a fix could
break something else) and the change needed in the code is simple.

If the code is changed to that shown below then it works.

int
f3(int a, int b, int (*f)(int, int))
{
    return f(a, b);
}

If the segfault is not a desired outcome then I could probably detect
the problem and "assert" an error instead of just crashing.

-- 
Andrew.
----------------------------------------------------------------------
Andrew M. Bishop                             a...@gedanken.demon.co.uk
                                      http://www.gedanken.demon.co.uk/

Cxref homepage:                 http://www.gedanken.demon.co.uk/cxref/



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to