On Tue, Jul 02, 2002 at 03:09:52PM +0900, R. Lahaye wrote:
> fontinfo * searchFont(string const & name)
> {
>       int const n = sizeof(fontinfos) / sizeof(fontinfo);
>       char dummy[9]; // dummy declaration, without being used !?!?
> 
>       for (int i = 0; i < n; ++i)
>               if (fontinfos[i].cmd_ == name) {
>                       return fontinfos + i;
>               }
>       return searchFont("mathnormal");
> }
> --------------------------------------------------
> 
> Somehow, this may force a correct stack management, or something.

I think it just introduces "padding" so that the stack corruption that we
see does not hit vital parts like some return address.

Could you initialize the dummy array with some special value and dump the
contents before you leave the function? 

Somebody is writing in there, and if we know what is written we may deduced
who is writing...

> Do you understand this, or does this show at last that there's obviously
> something fishy whith my compiler, when it comes to the string variables
> and the stack management? (it's gcc 2.95.3)

I am using the same, but it might be your architecture's backend.

> BTW: your own solution applied to CVS to avoid the recursion by
> "return fontinfos", works also fine here; since the recursion appears
> to be the culprit.

Hm. This could then be some optimization bug like re-using stackframes when
it really should not.

Could you try to remove any optimization (configure with -O0 or so)
and/or look at the produced assembler code?

what happens if you remove the 'const' from 'int const n'?

What happens if you remove the variable entirely and put the expression
directly into the for-condition?

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)

Reply via email to