This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Curious segmentation fault...


Shriramana Sharma writes:
 > Dear list,
 > 
 > Namaste (hello). This is my first post. I wonder if I have found a bug or at 
 > least an anomalous behaviour in GCC. Please download the file segfault.tar.gz 
 > from:
 > 
 > http://www.yousendit.com/transfer.php?action=download&ufid=0D3E9B791AE99BEA
 > 
 > (available for seven days from now). Do make and test both monthpan and 
 > monthpan-bug with any date range that contains a Sunday (which is where the 
 > bug lies). You should find that monthpan creates an output file called 
 > monthpan.txt whereas monthpan-bug creates a segmentation fault at 
 > grahanaama[0] (grahanaama means "weekday name").

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].

 > The only difference between the two source files monthpan.c and monthpan-bug.c 
 > is that the latter contains the line:
 > 
 > char spicanaama[] = "Spica";
 > 
 > *before* the start of the declarations of the two-dimensional arrays, which 
 > for some reason seems to cause the zero element of the first two-dimensional 
 > array to be out-of-bounds.
 > 
 > This problem confirmed on gcc-4.1/glibc-2.4 and gcc-3.35/glibc-2.34.
 > 
 > Please can anyone enlighten me as to what exactly causes this bug? Is it a bug 
 > with GCC? If yes, where do I report it?

Don't!

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]