473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Segmentation Fault

I just finish writing LAB2 with no errors when compiling, but once i run
it, i get "segmentation fault".. i don't know what is wrong, can anyoen
tell me what it means and how i can fix it? thx!

Nov 14 '05 #1
21 8194
us**@domain.invalid spoke thus:
I just finish writing LAB2 with no errors when compiling, but once i run
it, i get "segmentation fault".. i don't know what is wrong, can anyoen
tell me what it means and how i can fix it? thx!


You inadvertently drew a pentagram on your screen and thereby summoned
The Lord of Vague Usenet Postings, causing your error. That's just a
guess, however. Another guess is that LAB2, whatever the heck it was,
involved pointers or memory allocation, and that you messed it up.
"Segmentation fault" means that you did something wrong, but nothing
more can be gleaned from it without looking at your code. If you post
it, someone may be kind enough to help you.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #2
us**@domain.invalid wrote:

I just finish writing LAB2 with no errors when compiling,
but once i run it, i get "segmentation fault"
.. i don't know what is wrong, can anyoen
tell me what it means and how i can fix it? thx!


Write the smallest similar program that compiles
and gives the same runtime error. Then post the code.

--
pete
Nov 14 '05 #3
On Fri, 6 Feb 2004 us**@domain.invalid wrote:
I just finish writing LAB2 with no errors when compiling, but once i run
it, i get "segmentation fault".. i don't know what is wrong, can anyoen
tell me what it means and how i can fix it? thx!


It means you made a mistake in your program. The fix is to stop writing
bad code. Without further information I cannot be more specific.

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
Nov 14 '05 #4
us**@domain.invalid wrote:
I just finish writing LAB2 with no errors when compiling, but once i run
it, i get "segmentation fault".. i don't know what is wrong, can anyoen
tell me what it means and how i can fix it? thx!


Stop dereferencing invalid pointers.
--
Martin Ambuhl
Nov 14 '05 #5
>> I just finish writing LAB2 with no errors when compiling, but once i run
it, i get "segmentation fault".. i don't know what is wrong, can anyoen
tell me what it means and how i can fix it? thx!


Stop dereferencing invalid pointers.


What a guess :)
Do the statistics say so that it's most likely to be an invalid pointer?
Nov 14 '05 #6
"Jan Engelhardt" <je*****@linux01.gwdg.de> wrote in message
news:Pi******************************@yvahk01.tjqt .qr...
I just finish writing LAB2 with no errors when compiling, but once i run it, i get "segmentation fault".. i don't know what is wrong, can anyoen
tell me what it means and how i can fix it? thx!


Stop dereferencing invalid pointers.


What a guess :)
Do the statistics say so that it's most likely to be an invalid pointer?


Yes. The statistics show that 100% of segmentation faults are caused by
derefencing an invalid pointer.
Nov 14 '05 #7
Peter Pichler wrote:
"Jan Engelhardt" <je*****@linux01.gwdg.de> wrote in message
news:Pi******************************@yvahk01.tjqt .qr...
>> I just finish writing LAB2 with no errors when compiling, but once i run >> it, i get "segmentation fault".. i don't know what is wrong, can anyoen
>> tell me what it means and how i can fix it? thx!
>
>Stop dereferencing invalid pointers.


What a guess :)
Do the statistics say so that it's most likely to be an invalid pointer?


Yes. The statistics show that 100% of segmentation faults are caused by
derefencing an invalid pointer.


$ cat recurse.c
int main() { return main(); }
$ gcc -ansi -pedantic recurse.c
$ ./a.out
Segmentation fault

Jeremy.
Nov 14 '05 #8
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote in message
news:sl*******************@hehe.cl.cam.ac.uk...
Peter Pichler wrote:

Yes. The statistics show that 100% of segmentation faults are caused by
derefencing an invalid pointer.


$ cat recurse.c
int main() { return main(); }
$ gcc -ansi -pedantic recurse.c
$ ./a.out
Segmentation fault


Your example involves dereferencing an invalid pointer.
Nov 14 '05 #9
Peter Pichler wrote:
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote in message
news:sl*******************@hehe.cl.cam.ac.uk...
Peter Pichler wrote:
>
> Yes. The statistics show that 100% of segmentation faults are caused by
> derefencing an invalid pointer.


$ cat recurse.c
int main() { return main(); }
$ gcc -ansi -pedantic recurse.c
$ ./a.out
Segmentation fault


Your example involves dereferencing an invalid pointer.


Really? At which point, and for what reason, does the pointer become
invalid?

Jeremy.
Nov 14 '05 #10
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote in message
news:sl*******************@hehe.cl.cam.ac.uk...
Peter Pichler wrote:
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote in message
news:sl*******************@hehe.cl.cam.ac.uk...
Peter Pichler wrote:
>
> Yes. The statistics show that 100% of segmentation faults are caused by > derefencing an invalid pointer.

$ cat recurse.c
int main() { return main(); }
$ gcc -ansi -pedantic recurse.c
$ ./a.out
Segmentation fault


Your example involves dereferencing an invalid pointer.


Really? At which point, and for what reason, does the pointer become
invalid?


Isn't calling a function dereferencing a function pointer?
This is a genuine question, I am not so sure any more.

Peter
Nov 14 '05 #11
nrk
Peter Pichler wrote:
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote in message
news:sl*******************@hehe.cl.cam.ac.uk...
Peter Pichler wrote:
> "Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote in message
> news:sl*******************@hehe.cl.cam.ac.uk...
>> Peter Pichler wrote:
>> >
>> > Yes. The statistics show that 100% of segmentation faults are caused by >> > derefencing an invalid pointer.
>>
>> $ cat recurse.c
>> int main() { return main(); }
>> $ gcc -ansi -pedantic recurse.c
>> $ ./a.out
>> Segmentation fault
>
> Your example involves dereferencing an invalid pointer.
Really? At which point, and for what reason, does the pointer become
invalid?


Isn't calling a function dereferencing a function pointer?
This is a genuine question, I am not so sure any more.


I believe you're correct. (Since, I am watching my mouth as far as
interpreting the standard for the general public goes, I won't assert that
you're correct :-)

From 6.3.2.1:

4 A function designator is an expression that has function type. Except when
it is the operand of the sizeof operator54) or the unary & operator, a
function designator with type "function returning type" is converted to an
expression that has type "pointer to function returning type".

Further, 6.5.2.2 Function Calls:

1 The expression that denotes the called function77) shall have type pointer
to function returning void or returning an object type other than an array
type.

77) Most often, this is the result of converting an identifier that is a
function designator.

-nrk.
Peter


--
Remove devnull for email
Nov 14 '05 #12
Peter Pichler wrote:

"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote in message
news:sl*******************@hehe.cl.cam.ac.uk...
Peter Pichler wrote:
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote in message
news:sl*******************@hehe.cl.cam.ac.uk...
> Peter Pichler wrote:
> >
> > Yes. The statistics show that 100% of segmentation faults are caused by> > derefencing an invalid pointer.
>
> $ cat recurse.c
> int main() { return main(); }
> $ gcc -ansi -pedantic recurse.c
> $ ./a.out
> Segmentation fault

Your example involves dereferencing an invalid pointer.


Really? At which point, and for what reason, does the pointer become
invalid?


Isn't calling a function dereferencing a function pointer?
This is a genuine question, I am not so sure any more.


The second appearance of `main' is in fact a function
pointer, and the `()' function-call operator uses that pointer
value to determine what function to invoke. Whether this use
constitutes a "dereference" is unclear -- the Standard neither
defines nor uses the word.

At any rate, the function pointer value `main' remains
valid for the life of the program. Thus, the call is not
"dereferencing an invalid pointer" because the pointer is
not invalid.

--
Er*********@sun.com
Nov 14 '05 #13
On 6 Feb 2004 22:22:58 GMT, in comp.lang.c , Jeremy Yallop
<je****@jdyallop.freeserve.co.uk> wrote:
Peter Pichler wrote:
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote in message
news:sl*******************@hehe.cl.cam.ac.uk...
Peter Pichler wrote:
>
> Yes. The statistics show that 100% of segmentation faults are caused by
> derefencing an invalid pointer.

$ cat recurse.c
int main() { return main(); }
$ gcc -ansi -pedantic recurse.c
$ ./a.out
Segmentation fault


Your example involves dereferencing an invalid pointer.


Really? At which point, and for what reason, does the pointer become
invalid?


when you run out of memory .

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #14
MSG
Martin Ambuhl <ma*****@earthlink.net> wrote in message news:<DT*******************@newsread1.news.atl.ear thlink.net>...
us**@domain.invalid wrote:
I just finish writing LAB2 with no errors when compiling, but once i run
it, i get "segmentation fault".. i don't know what is wrong, can anyoen
tell me what it means and how i can fix it? thx!


Stop dereferencing invalid pointers.


What happened to our OTNs (off-topic Nazis). Why aren't they stomping
the guts out of these people saying "segmentation ain't in our
bible^Wstandard!" :-)

MSG (no, I'm not an OTN)
Nov 14 '05 #15
us**@domain.invalid wrote:
I just finish writing LAB2 with no errors when compiling
but once i run it, I get "segmentation fault".
I don't know what is wrong,
Can anyone tell me what it means and how I can fix it?


Your program is attempting to reference memory
which doesn't belong to it.
You probably have an array index which is "out-of-bounds".
Use your debugger. If you don't have a debugger or know how to use it,
you can insert statements to print diagnostic messages

fprintf(stderr, "Got to this point in the program!\n"); fflush(stderr);

Put the first one smack dab in the middle of your code.
If you get the "segmentation fault" before the diagnostic message
you know that the error is before the print statement and
the error is after the print statement
if you get the diagnostic message before the "segmentation fault".
A short binary search usually locates the error quickly.

Nov 14 '05 #16
Jeremy Yallop wrote:
Peter Pichler wrote:
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote
Peter Pichler wrote:
>
> Yes. The statistics show that 100% of segmentation faults
> are caused by derefencing an invalid pointer.

$ cat recurse.c
int main() { return main(); }
$ gcc -ansi -pedantic recurse.c
$ ./a.out
Segmentation fault


Your example involves dereferencing an invalid pointer.


Really? At which point, and for what reason, does the pointer
become invalid?


Also, what pointer? To make sure, add void in "int main(void)"

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #17
Eric Sosman wrote:
Peter Pichler wrote:
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote
Peter Pichler wrote:
> "Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote
>> Peter Pichler wrote:
>> >
>> > Yes. The statistics show that 100% of segmentation faults
>> > are caused by derefencing an invalid pointer.
>>
>> $ cat recurse.c
>> int main() { return main(); }
>> $ gcc -ansi -pedantic recurse.c
>> $ ./a.out
>> Segmentation fault
>
> Your example involves dereferencing an invalid pointer.

Really? At which point, and for what reason, does the
pointer become invalid?


Isn't calling a function dereferencing a function pointer?
This is a genuine question, I am not so sure any more.


The second appearance of `main' is in fact a function
pointer, and the `()' function-call operator uses that pointer
value to determine what function to invoke. Whether this use
constitutes a "dereference" is unclear -- the Standard neither
defines nor uses the word.

At any rate, the function pointer value `main' remains
valid for the life of the program. Thus, the call is not
"dereferencing an invalid pointer" because the pointer is
not invalid.


I was going to be a smart-ass and point out that compiling with
gcc -O2 did not generate the segment fault, because of tail
recursion optimization. Luckily I tried it first, and found that
gcc does NOT optimize this one. Must be a feature, couldn't
possibly be a bug.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #18
In 'comp.lang.c', "E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote:
fprintf(stderr, "Got to this point in the program!\n"); fflush(stderr);


I'm not sure thar stderr is buffered, hence the fflush() seems redunant.
Also, the line is terminated by a '\n', that makes the fflush() twice
redundant. What would be more informative would have been to add smart
information like the file name and the line in the file:

fprintf (stderr, "Got to here %s:%d in the program!\n", __FILE__, __LINE__);

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=cpp
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #19
"Emmanuel Delahaye" <em**********@noos.fr> wrote in message
news:Xn***************************@212.27.42.68...
In 'comp.lang.c', "E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote:
fprintf(stderr, "Got to this point in the program!\n"); fflush(stderr);


I'm not sure thar stderr is buffered, hence the fflush() seems redunant.
Also, the line is terminated by a '\n', that makes the fflush() twice
redundant. What would be more informative would have been to add smart
information like the file name and the line in the file:

fprintf (stderr, "Got to here %s:%d in the program!\n", __FILE__,

__LINE__);

A nitpick here is that __LINE__ is not guaranteed to have int type.

--
Peter
Nov 14 '05 #20
On 6 Feb 2004 17:52:11 -0800, ms*****@yahoo.com (MSG) wrote:
Martin Ambuhl <ma*****@earthlink.net> wrote in message news:<DT*******************@newsread1.news.atl.ear thlink.net>...
us**@domain.invalid wrote:
> I just finish writing LAB2 with no errors when compiling, but once i run
> it, i get "segmentation fault".. i don't know what is wrong, can anyoen
> tell me what it means and how i can fix it? thx!
>


Stop dereferencing invalid pointers.


What happened to our OTNs (off-topic Nazis). Why aren't they stomping
the guts out of these people saying "segmentation ain't in our
bible^Wstandard!" :-)

You must distinguish between the thread title ("Segmentation Fault")
and the topic (invalid pointers.)

BTW, what's the "^W" for?

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #21
Alan Balmer <al******@att.net> scribbled the following:
On 6 Feb 2004 17:52:11 -0800, ms*****@yahoo.com (MSG) wrote:
What happened to our OTNs (off-topic Nazis). Why aren't they stomping
the guts out of these people saying "segmentation ain't in our
bible^Wstandard!" :-)
You must distinguish between the thread title ("Segmentation Fault")
and the topic (invalid pointers.)

BTW, what's the "^W" for?


Old "ed" command, meaning "delete the previous word". Understood in
informal context to mean "no, I mean".

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am lying."
- Anon
Nov 14 '05 #22

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

Similar topics

2
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...
3
by: diyanat | last post by:
i am writing a cgi script in C using the CGIC library, the script fails to run, i am using apache on linux error report from apache : internal server error Premature end of script headers:...
16
by: laberth | last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why? Here is what I use : typedef struct noeud { int val; struct noeud *fgauche; struct noeud *fdroit; } *arbre; //for those...
3
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc...
5
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...
18
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)?...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
7
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our...
3
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...
6
by: DanielJohnson | last post by:
int main() { printf("\n Hello World"); main; return 0; } This program terminate just after one loop while the second program goes on infinitely untill segmentation fault (core dumped) on...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.