This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Curious segmentation fault... SOLVED
Shriramana Sharma writes:
> Tuesday 23 May 2006 19:10 samaye, Andrew Haley alekhiit:
>
> > You call swe_fixstar with the argument 0 (star) = spicanaama.
> > swe_fixstar does
> > sprintf(star, "%s,%s", cpos[0], cpos[1])
> > so, it overwrites its input argument (spicanaama). But spicanaama
> > isn't big enough to contain the resulting string, so it overwites the
> > next variable, which is grahanaama[0].
>
> Thanks. Changing the size of spicanaama to 41 solved the problem.
In the version you posted it was
char spicanaama[] = "Spica";
which is 6 bytes long.
It is unfortunate that the string that is the first argument of
swe_fixstar is used as an input and then it is overwritten. That
isn't your fault, of course, but it is bad style and leads to bugs
such as this one.
Andrew.