473,769 Members | 6,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Segmentation Fault on Linux, but not on Solaris

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.
Nov 13 '05 #1
9 6555
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.

Nov 13 '05 #2
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

--
Er*********@sun .com
Nov 13 '05 #3
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 no****@mega-nerd.com (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
Nov 13 '05 #4
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

Nov 13 '05 #5

"Allin Cottrell" <co******@wfu.e du> wrote in message
news:bo******** ***@f1n1.spenet .wfu.edu...

(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
Nov 13 '05 #6
Mac
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
--

Nov 13 '05 #7
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 (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 13 '05 #8

"Erik de Castro Lopo" <no****@mega-nerd.com> wrote in message news:3F******** *******@mega-nerd.com...
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.
Nov 13 '05 #9
In <9e************ **************@ posting.google. com> xl*****@yahoo.c om (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: Da*****@ifh.de
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6809
by: sivignon | last post by:
Hi, I'm writing a php script which deals with 3 ORACLE databases. This script is launch by a script shell on an linux machine like this : /../php/bin/php ./MySript.php (PHP 4.3.3) My script works fine and do all what I need. But at the end of the execution, I can read "Segmentation Fault". The segmentation fault appear at the end of my script execution,
0
1195
by: ldvmbs | last post by:
Hi, I am trying to parse an xml file on Sun Solaris using C++ and Xerces. The code works on windows but when I ported it to Sun Solaris I am getting a Segmentation Fault in the begining of the parsing during the fatalError method. I get the same error if the xml document doesn't exist at all. Please help...
5
2567
by: Allan | last post by:
Hi all, I've a C program which was originally developed under Sun Solaris(OS,2.6,gcc 2.95). I'm trying to migrate it to our linux system(Mandrake 9.0,2.4.19,gcc 3.2). Following is the MAKEFILE: CC=gcc
3
2124
by: I_have_nothing | last post by:
Hi! I am new in C. I got a lots of "Segmentation Fault"s in my code. I guess One possibility is: if " int array_i; " is declard and the code trys to access "array_i", a Segmentation Fault will be returned by gcc compiler on linux. What are the other "major" reasons to have "Segmentation Fault"? I hope this is not a stupid question and someone is will to give me some exampls(part of code) with errors a newer might esasily make and
5
2998
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I understood that a segmentation fault can occur whenever I declare a pointer and I leave it un-initialized. So I thought the problem here is with the (const char *)s in the stuct flightData (please note that I get the same fault declaring as char * the...
18
26121
by: Digital Puer | last post by:
Hi, I'm coming over from Java to C++, so please bear with me. In C++, is there a way for me to use exceptions to catch segmentation faults (e.g. when I access a location off the end of an array)? Thanks.
5
6753
by: silverburgh.meryl | last post by:
Hi, I have a segmentation fault in line 66 of GroupResult.h and I can't figure out why that causes any problem, I appreciate if anyone can help. line 66 of Result.h: 66 size_t size() const { return _bdl.size(); }
6
5196
by: g35rider | last post by:
Hi, sometimes due to unchecked code I get segmentation faults once in a while and would like to be able to catch them and do some cleanup on things. This segmentation fault could be anywhere in the code. Could it be caught like a signal and perform cleanup then? Or would I have to put every piece of function code in try and catch blocks? Thanks Ankur
3
5187
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection from 10g release2 PHP is configured with the following parameters './configure' '--prefix=/opt/oracle/php' '--with-apxs=/opt/oracle/apache/bin/apxs' '--with-config-file-path=/opt/oracle/apache/conf' '--enable-safe-mode' '--enable-session'...
0
9587
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.