Segmentation Fault on Linux, but not on Solaris

J

John

I'm getting a segmentation fault when I try to realloc memory.

This only happens when I compile using gcc v. 3.2 on Red Hat Linux 8.0
3.2-7. When I compile on Solaris 5.7 using gcc v. 2.95.2, the error
does not occur.

Is there a way to solve this using compiler options, or any other
method? In the end, I need this program to compile on the Linux box.

Any help would be greatly appreciated!!!
Thanks.
 
A

Artie Gold

John said:
I'm getting a segmentation fault when I try to realloc memory.

This only happens when I compile using gcc v. 3.2 on Red Hat Linux 8.0
3.2-7. When I compile on Solaris 5.7 using gcc v. 2.95.2, the error
does not occur.

Is there a way to solve this using compiler options, or any other
method? In the end, I need this program to compile on the Linux box.
Most likely, you've corrupted your free store (often known as the
`heap'), which causes undefined behavior. Since `seems to work' is
one of the possible outcomes of UB...

IOW, there's a bug in your program (most likely a buffer overrun,
but I'm guessing). The difference in behavior you're seeing, BTW,
most likely has more to do with the underlying implementation of the
standard library on the two platforms as opposed to the compiler used.

HTH,
--ag
 
E

Erik de Castro Lopo

John said:
I'm getting a segmentation fault when I try to realloc memory.

This only happens when I compile using gcc v. 3.2 on Red Hat Linux 8.0
3.2-7. When I compile on Solaris 5.7 using gcc v. 2.95.2, the error
does not occur.

Is there a way to solve this using compiler options, or any other
method? In the end, I need this program to compile on the Linux box.

Any help would be greatly appreciated!!!

Since the problem is on Linux, you can try running it
with valgrind (search http://freshmeat.net/ ) which is
really good at finding these kinds of errors. Unfortunately
it only runs ix86 Linux.

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo (e-mail address removed) (Yes it's valid)
+-----------------------------------------------------------+
IDIOT, n.
A member of a large and powerful tribe whose influence in human
affairs has always been dominant and controlling. The Idiot's
activity is not confined to any special field of thought or action,
but "pervades and regulates the whole." He has the last word in
everything; his decision is unappealable. He sets the fashions and
opinion of taste, dictates the limitations of speech and
circumscribes conduct with a dead-line.
Ambrose Bierce
 
A

Allin Cottrell

Artie said:
Most likely, you've corrupted your free store (often known as the
`heap'), which causes undefined behavior.

Agreed. I am author of a cross-platform C program. In the "early days"
I used to think (e.g.) "It works fine on Linux but 'performs an
illegal operation' on Windows, what the heck is wrong with Windows?"
Well, OK, there are plenty of things wrong with Windows, but my
point is that, as I have learned, with very high probability it's
a bug in your/my code that "happens to" show itself as a segfault on
one platform even though it seems to "work fine" on another.

Actually, the overt appearance of a segfault is good! It forces
you to track down the bug -- e.g. with valgrind

http://developer.kde.org/~sewardj/
 
G

Glen Herrmannsfeldt

(snip)
Agreed. I am author of a cross-platform C program. In the "early days"
I used to think (e.g.) "It works fine on Linux but 'performs an
illegal operation' on Windows, what the heck is wrong with Windows?"
Well, OK, there are plenty of things wrong with Windows, but my
point is that, as I have learned, with very high probability it's
a bug in your/my code that "happens to" show itself as a segfault on
one platform even though it seems to "work fine" on another.

I once had a program with an (accidental) uninitialized variable that worked
on one system and not on another. It turned out that my program depended on
it NOT being initialized to zero, and one system did initialize it to zero.

-- glen
 
M

Mac

I'm getting a segmentation fault when I try to realloc memory.

This only happens when I compile using gcc v. 3.2 on Red Hat Linux 8.0
3.2-7. When I compile on Solaris 5.7 using gcc v. 2.95.2, the error
does not occur.

Is there a way to solve this using compiler options, or any other
method? In the end, I need this program to compile on the Linux box.

Any help would be greatly appreciated!!!
Thanks.

The way your question is written, you almost make it sound like the
compiler is segfaulting.

But I gather that it is your compiled executable, not the compiler. The
most likely explanation is that you have a bug in your code. The only
compiler flags which are likely to help are the ones which perform checks
on your code to warn against possible bugs. (e.g., -Wall -pedantic)

If you can simplify the code to the smallest example which still exhibits
the segfault, making sure in the process to remove any platform dependent
stuff which would make it fail to compile on other platforms, then you can
post the code here and I am sure someone will find the problem.

If you do this, make sure you cut and paste the program, otherwise all the
feedback you get will probably be over a typo. ;-)

Mac
--
 
C

CBFalconer

John said:
I'm getting a segmentation fault when I try to realloc memory.

This only happens when I compile using gcc v. 3.2 on Red Hat Linux
8.0 3.2-7. When I compile on Solaris 5.7 using gcc v. 2.95.2, the
error does not occur.

Is there a way to solve this using compiler options, or any other
method? In the end, I need this program to compile on the Linux box.

Any help would be greatly appreciated!!!

You probably have an error in line 242. At least that is the best
we can do with the prodigious source code you have supplied. I.E.
cut the problem down to a compilable source of about 100 lines or
less which demonstrates the problem, and post that here. Paste
compilable source, not your approximation of such. Then possibly
someone may be able to point out the error.
 
D

Don Porges

Erik de Castro Lopo said:
Since the problem is on Linux, you can try running it
with valgrind (search http://freshmeat.net/ ) which is
really good at finding these kinds of errors. Unfortunately
it only runs ix86 Linux.

Let me extend your suggestion: *whether or not the problem is
seen on Linux*, you can try valgrind and see what it says. Remember, if the problem
is an uninitialized variable, or a bad use of malloc or free, valgrind's analysis will find it
even if it doesn't cause a crash in that environment.
 
D

Dan Pop

In said:
I'm getting a segmentation fault when I try to realloc memory.

This only happens when I compile using gcc v. 3.2 on Red Hat Linux 8.0
3.2-7. When I compile on Solaris 5.7 using gcc v. 2.95.2, the error
does not occur.

Is there a way to solve this using compiler options, or any other
method? In the end, I need this program to compile on the Linux box.

Sure. Use the -fix-my-bugs compiler option.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top