[LCP]Segmentation Fault

Paul Gearon gearon at ieee.org
Wed Feb 22 22:46:02 UTC 2006


The fact that it works in some conditions (ie. on one Redhat build)  
but not others is just a function of the memory layout of the  
system.  The important fact is that fails with a segv.  I doubt that  
there's any significance to it passing on certain systems.

This sounds like a classic stack smash.  The giveaway was the segv  
moving when you commented out the offending line.

Check your printf statements (printing more/less than the arguments  
you provide, or the wrong types).  Make sure you're not over running  
on your strings/arrays.  K&R C also let you provide the wrong number  
or size of arguments to functions.

What else?  Oh, a fun one is to return a pointer to a value on the  
stack.  :-)

Have fun finding it.  Stack smashes can be tough to find, but they  
usually teach you something useful.

Regards,
Paul


On Feb 22, 2006, at 1:09 AM, Dhaval Mehta wrote:

> Hello Everybody,
>
> I have a C program which executes successfully on RedHat 8.0 gcc
> version 3.2.When i execute the same program on different machine
> having Fedora Core gcc version 3.3.2 it gives the Segmentation
> fault.When i used gdb tool for debugging i got the following message:-
> Program received signal SIGSEGV, segmentation fault
> build() at "program.c":2862
> So when i comment the line 2862 which is a initialisation statement
> and again use gdb,i get error at some other line.
> Also this program was translated using P2C which was installed
> separately for both the machines (Pascal to C translator).
> Please guide me.
> Thank You.
>
> Dhaval.
>
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List





More information about the linuxCprogramming mailing list