Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Segmentation Fault on Linux, but not on Solaris

Reply
Thread Tools

Segmentation Fault on Linux, but not on Solaris

 
 
John
Guest
Posts: n/a
 
      11-07-2003
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.
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      11-07-2003
John wrote:
>
> I'm getting a segmentation fault when I try to realloc memory.
> [...]


This is Question 7.19 in the comp.lang.c Frequently
Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      11-07-2003
John wrote:
> 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

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

 
Reply With Quote
 
Erik de Castro Lopo
Guest
Posts: n/a
 
      11-07-2003
John wrote:
>
> 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 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
 
Reply With Quote
 
Allin Cottrell
Guest
Posts: n/a
 
      11-08-2003
Artie Gold wrote:
> John wrote:
>
>> 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.


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/


--
Allin Cottrell
Department of Economics
Wake Forest University, NC

 
Reply With Quote
 
Glen Herrmannsfeldt
Guest
Posts: n/a
 
      11-08-2003

"Allin Cottrell" <(E-Mail Removed)> wrote in message
news:bohil1$340o$(E-Mail Removed)...

(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


 
Reply With Quote
 
Mac
Guest
Posts: n/a
 
      11-08-2003
On Fri, 07 Nov 2003 12:36:43 +0000, John wrote:

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

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      11-08-2003
John wrote:
>
> 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.

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
Don Porges
Guest
Posts: n/a
 
      11-08-2003

"Erik de Castro Lopo" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> John wrote:
> >
> > 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.


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.


 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      11-10-2003
In <(E-Mail Removed) > (E-Mail Removed) (John) writes:

>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
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java JDesktop GUI Segmentation Fault on first use in CDE (Solaris 10)Until I Logout and Log Back in brianjester@gmail.com Java 2 05-15-2012 04:48 AM
Segmentation fault but now errors when running Valgrind carl C++ 5 12-01-2009 08:49 AM
Segmentation Fault (core dumped) on Solaris 10 mariakvelasco@gmail.com Perl Misc 4 01-10-2008 10:49 PM
access of memory beyond allocation, not causing segmentation fault... sam_cit@yahoo.co.in C Programming 21 05-13-2007 11:18 AM
Xerces on Solaris - Segmentation fault ldvmbs@gmail.com XML 0 05-16-2005 07:21 AM



Advertisments