Segmentation fault

Segmentation fault

Post by Dimitri I. Rakiti » Sat, 17 Jun 1995 04:00:00




: I'm trying to write some utility programs and I'm having trouble.  They
: compile fine but, when I run it, it dies instantly!

Guess what? I have exactly the same problem at work every day (writing
real time sound processing for Windows95/NT). Compiles fine but sometimes
dies ;-)))
Dimitri

 
 
 

Segmentation fault

Post by Koyama Tadayos » Sat, 17 Jun 1995 04:00:00


  Try "debug" your program. (No, there are no "debug" command in
linux. It means "find-the-problem-in-your-code-and-repair-them").

--
#  I setup my (ding)Gnus to kill out all articles from NiftyServe.
# Please mail me if it seems that I don't read you and you want be
# read by me.

 
 
 

Segmentation fault

Post by Brandon Mikkels » Sat, 17 Jun 1995 04:00:00



Quote:

>I'm trying to write some utility programs and I'm having trouble.  They
>compile fine but, when I run it, it dies instantly!
>I'm running Linux 1.2.9 and gcc 2.5.8 on a 486SX33 with 8MB RAM (phys) and
>20MB (swap).  I compile with:
>   cc prog.c
>Anybody have any ideas?

>Thanks in advance!
>Dave

I'm having the same problem.  I've got kernel versions 1.2.3 and 1.2.8 with the
gcc compiler 2.6.3 on both 486dx2s and pentium 90s.  
I've tried about everything, but the images just won't work.  Everything except
the kernel.  I can get that to compile perfectly.  Is it the compiler, the
libraries, the kernel itself?   at this point I'm about ready to go back to
1.1.95, so any help would be greatly appreciated.
Thanks in advance.
Brandon
 
 
 

Segmentation fault

Post by David G. Komlo » Sat, 17 Jun 1995 04:00:00


I'm trying to write some utility programs and I'm having trouble.  They
compile fine but, when I run it, it dies instantly!
I'm running Linux 1.2.9 and gcc 2.5.8 on a 486SX33 with 8MB RAM (phys) and
20MB (swap).  I compile with:
   cc prog.c
Anybody have any ideas?

Thanks in advance!
Dave

 
 
 

Segmentation fault

Post by Michael Kausch » Tue, 20 Jun 1995 04:00:00



: I'm trying to write some utility programs and I'm having trouble.  They
: compile fine but, when I run it, it dies instantly!
: I'm running Linux 1.2.9 and gcc 2.5.8 on a 486SX33 with 8MB RAM (phys) and
: 20MB (swap).  I compile with:
:    cc prog.c
: Anybody have any ideas?

: Thanks in advance!
: Dave

His must the first real evil UNIX virus. I've got the same problem on my SUN
for several years. It must be a programing snoop virus as it always
happens when I write my own code. Someone told me that you can get a
fast and final remedy by turning the CPU on the motherboard by 180 deg.
        mka
    ---WER UMLAUTE BENUTZT, FRI T AUCH KLEINE KINDER !!---
Michael Kauschke                                    |     |\  |-\

phone  : 0531-3917454                               |   | |\  |  

 
 
 

Segmentation fault

Post by Craig Taverne » Tue, 20 Jun 1995 04:00:00


Quote:> >I'm trying to write some utility programs and I'm having trouble.  They
> >compile fine but, when I run it, it dies instantly!
> I'm having the same problem.  I've got kernel versions 1.2.3 and 1.2.8 with the
> gcc compiler 2.6.3 on both 486dx2s and pentium 90s.  
> I've tried about everything, but the images just won't work.  Everything except
> the kernel.  I can get that to compile perfectly.  Is it the compiler, the
> libraries, the kernel itself?   at this point I'm about ready to go back to
> 1.1.95, so any help would be greatly appreciated.
> Thanks in advance.
> Brandon

I'm having exactly the same problem with the same setup (486dx4/100 and
pentium 100 with 1.2.3 and 1.2.8).  Many of my own C programs that have
been running fine for ages under the previous versions (and on other unix
systems too) are now giving instant segmentation faults (and other weird
stuff during make too).  I'm under the impression it has something to do
with the libraries (strace showed exit immediately after a library load
and the make errors were definitely library related -> /usr/libg.sa).

Personnally I think this IS a serious error and not just a coincidence
that several people are simultaneously having programming lapses
(especially since some code has been working fine under previous linux's
and has not been changed).

If someone out there has any idea what the problem could possibly be, I'd
really appreciate some help.  It sound like a few others would too.

Thanks, Craig

"If God had meant us to be *, we would have been born that way."

Craig Taverner
Structural Chemistry, University of the Witwatersrand, South Africa

 
 
 

Segmentation fault

Post by Jesper de Jon » Wed, 21 Jun 1995 04:00:00



...

Quote:> Example:
> (This will fail)
> void main(void)
> {
>   char *test[20];

>   sprintf(test, "Hello, world!");
> }

Don't you see this is *wrong* ?!? You create an array containing 20
pointers to char and then put a string in that space!

Quote:> (This will work)
> void main(void)
> {
>   char *test[20];

>   sprintf((char *)test, "Hello, world!");
> }

Equally bad C code. It does the same as above: create an array containing
20 pointers to char, then treats this as an array of char...!!! Probably
you meant to do this:

void main(void)
{
  char test[20];   /* an array containing 20 chars */

  sprintf(test, "Hello, world!");

Quote:}

In the line with sprintf, test is treated as &test[0], the address of the
first char in your array. Read a good book about programming in C!

 - Jesper.

-------------------------------------------------

-------------------------------------------------

 
 
 

Segmentation fault

Post by David G. Komlo » Wed, 21 Jun 1995 04:00:00




>: I'm trying to write some utility programs and I'm having trouble.  They
>: compile fine but, when I run it, it dies instantly!

>Guess what? I have exactly the same problem at work every day (writing
>real time sound processing for Windows95/NT). Compiles fine but sometimes
>dies ;-)))
>Dimitri

I'm still not sure what causes this problem but, it has to do with invalid
typecasting.  For example if I have a variable of type char * and pass it
to func(char *) it will die with a segmentation fault.  If I typcast the
variable as a (char *) when I pass it, the program will work fine.

Example:
(This will fail)
void main(void)
{
  char *test[20];

  sprintf(test, "Hello, world!");

Quote:}

(This will work)
void main(void)
{
  char *test[20];

  sprintf((char *)test, "Hello, world!");

Quote:}

I hope this helps! Thanks to everyone who sent me suggestions and comments!

Dave

 
 
 

Segmentation fault

Post by Jason Mcmull » Wed, 21 Jun 1995 04:00:00



: I'm still not sure what causes this problem but, it has to do with invalid
: typecasting.  For example if I have a variable of type char * and pass it
: to func(char *) it will die with a segmentation fault.  If I typcast the
: variable as a (char *) when I pass it, the program will work fine.

: Example:
: (This will fail)
: void main(void)
: {
:   char *test[20];
         ^^^^^^^^^
               \_____ Why are you creating an _array_ of pointers to strings?
    char test[20];
         ^^^^^^^^^
               \_____ Does what you want

:   sprintf(test, "Hello, world!");
: }

: (This will work)
: void main(void)
: {
:   char *test[20];

:   sprintf((char *)test, "Hello, world!");
: }

: I hope this helps! Thanks to everyone who sent me suggestions and comments!
: Dave

--

Microsoft  Network  is prohibited  from  redistributing  this work  in
any  form,  in whole  or  in  part. License  to distribute  this  post
is  available  to  Microsoft  Corp.  for  $1000. Distribution  without
permission constitutes an agreement to these terms.

 
 
 

Segmentation fault

Post by H. Peter Anv » Thu, 22 Jun 1995 04:00:00




In newsgroup: comp.os.linux.development.apps

Quote:

> void main(void)
> {
>   char test[20];   /* an array containing 20 chars */

>   sprintf(test, "Hello, world!");
> }

> In the line with sprintf, test is treated as &test[0], the address of the
> first char in your array. Read a good book about programming in C!

You should #include <stdio.h> (when using functions, always #include
the appropriate header files.)

Also, void main(void) is actually illegal, it should be:

int main(int argc, char *argv[])
^^^

int main() is OK, but void main(void) can actually generate invalid
code on some platforms (and will return a random exit status to your
program).

        /hpa
--

"The earth is but one country, and mankind its citizens."  --  Baha'u'llah

 
 
 

Segmentation fault

Post by Keith Rowla » Fri, 23 Jun 1995 04:00:00



Quote:> > >I'm trying to write some utility programs and I'm having trouble.  They
> > >compile fine but, when I run it, it dies instantly!
> > I'm having the same problem.  I've got kernel versions 1.2.3 and 1.2.8 with the
> > gcc compiler 2.6.3 on both 486dx2s and pentium 90s.  
> I'm having exactly the same problem with the same setup (486dx4/100 and
> pentium 100 with 1.2.3 and 1.2.8).  Many of my own C programs that have
> been running fine for ages under the previous versions (and on other unix
> systems too) are now giving instant segmentation faults (and other weird

By any chance, have any of you just installed XFree86? I had a program
running under iBCS (SCO emulation) working OK, until I loaded X-Windows.
Now it gives Segmentation Faults. I will try to unload X and see.

Best Regards, Keith in Mesa, Arizona
--

WWWURL: <a href="http://www.primenet.com/~keithr/">My Homepage</a>
   __   _
  / /  (_)__  __ ____  __
 / /__/ / _ \/ // /\ \/ /  . . .  t h e   c h o i c e   o f   a
/____/_/_//_/\_,_/ /_/\_\              G N U   g e n e r a t i o n . . .

 
 
 

Segmentation fault

Post by Gordon M » Fri, 23 Jun 1995 04:00:00




: ...
: > Example:
: > (This will fail)
: > void main(void)
: > {
: >   char *test[20];
: >
: >   sprintf(test, "Hello, world!");
: > }

: Don't you see this is *wrong* ?!? You create an array containing 20
: pointers to char and then put a string in that space!

Hold on. Although it is bad code, it should work. If the original poster
claims that it will core dump on sprintf() or somewhere in this program,
something else is wrong. char* test[20] is a  20 * sizeof(char*)
contiguous space. Usually, it will be 80 bytes comparing with 20 bytes
for char test[20].

It should work with or without casting.

: > (This will work)
: > void main(void)
: > {
: >   char *test[20];
: >
: >   sprintf((char *)test, "Hello, world!");
: > }

: Equally bad C code. It does the same as above: create an array containing
: 20 pointers to char, then treats this as an array of char...!!! Probably
: you meant to do this:

Again, Bad code but should not core dump and it should behave like
without the casting.

I think we still do not have information about the original poster's
problem. Can you (the original poster) tell us when it core dump?  Is it
in sprintf() or somewhere which is not mentioned in the program?

--
Gordon Man

 
 
 

Segmentation fault

Post by Craig Taverne » Fri, 23 Jun 1995 04:00:00


Quote:> : I'm trying to write some utility programs and I'm having trouble.  They
> : compile fine but, when I run it, it dies instantly!
> : I'm running Linux 1.2.9 and gcc 2.5.8 on a 486SX33 with 8MB RAM (phys) and
> : 20MB (swap).  I compile with:
> :    cc prog.c
> : Anybody have any ideas?

I've been fighting this problem now for several weeks.  In fact ever
since I installed the Slackware 2.3 on my four linux boxes.  After trying
everything possible I have finally found a possible lead:
If I compile my programs on an older linux machine (1.0.9 with gcc 2.5.8)
not only does it work well there, but the resulting binary works fine
under the newer linux's (1.2.8 gcc 2.6.3).  This seems to indicate to me
that the problem is most likely not with the kernel or the libraries, but
with the gcc2.6.3 itself.  I'm now trying (and failing) to install the
pentium version of gcc2.5.8 on the one machine to try and fix this.

Does anyone know where I can get precompiled binary distributions of
gcc2.5.8 for i486 (and possible also pentium)?  I'm having trouble
compiling the gcc2.5.8 source (possibly because of the gc2.6.3 bug |-< ).

Any advice, comments, or whatever, welcome.

Thanks, Craig

"If God had meant us to be *, we would have been born that way."

Craig Taverner
Structural Chemistry, University of the Witwatersrand, South Africa

 
 
 

Segmentation fault

Post by Sembiring_Ja » Sat, 24 Jun 1995 04:00:00



Quote:>> >I'm trying to write some utility programs and I'm having trouble.  They
>> >compile fine but, when I run it, it dies instantly!
>> I'm having the same problem.  I've got kernel versions 1.2.3 and 1.2.8 with the
>I'm having exactly the same problem with the same setup (486dx4/100 and
>pentium 100 with 1.2.3 and 1.2.8).  Many of my own C programs that have

i've got the same problem too (compiling and running khoros) on my new system. pentium 100, kernel 1.2.6 and gcc 2.6.3. The same program running on my old machine kernel 1.1.74 with gcc 2.5.8 on 486DX-2. No error on compiling. but when i run cantata it dies, segmentation fault.

i've got no idea what's going on, any help would be appreciated.
thank's in advanced.

--
                        Sembiring_Jaka

 
 
 

Segmentation fault

Post by David G. Komlo » Mon, 26 Jun 1995 04:00:00





>: ...
>: > Example:
>: > (This will fail)
>: > void main(void)
>: > {
>: >   char *test[20];
>: >
>: >   sprintf(test, "Hello, world!");
>: > }

>: Don't you see this is *wrong* ?!? You create an array containing 20
>: pointers to char and then put a string in that space!

>Hold on. Although it is bad code, it should work. If the original poster
>claims that it will core dump on sprintf() or somewhere in this program,
>something else is wrong. char* test[20] is a  20 * sizeof(char*)
>contiguous space. Usually, it will be 80 bytes comparing with 20 bytes
>for char test[20].

>It should work with or without casting.

>: > (This will work)
>: > void main(void)
>: > {
>: >   char *test[20];
>: >
>: >   sprintf((char *)test, "Hello, world!");
>: > }

>: Equally bad C code. It does the same as above: create an array containing
>: 20 pointers to char, then treats this as an array of char...!!! Probably
>: you meant to do this:

>Again, Bad code but should not core dump and it should behave like
>without the casting.

>I think we still do not have information about the original poster's
>problem. Can you (the original poster) tell us when it core dump?  Is it
>in sprintf() or somewhere which is not mentioned in the program?

>--
>Gordon Man


Being the original poster, I'd like to clarify a few things...  First, it
wasn't this program that core dumped, it was another one that I was having
problems with.  With this program I just get segmentation faults (let me
know if these two terms are synonimous (sp?)).  Yes, it
is poor programming style and I've since fixed my variable declarations.  I
still get segmentation faults though, at any point that I access data
outside of my arrays.  The segmentation fault wasn't what I was expecting
as an error since under DOS if you do the same thing it will just merrily
go on it's way and do *exactly* what you tell it to.
I don't know if this error is correct for Linux or if there is some other
problem, but I would recommend to anyone else with this error to seriously
inspect their array code.

Dave

 
 
 

1. Compiling *** VIM 5.3 *** Segmentation Fault..what is Seg-Fault..MEM Bounds?

Compiled fine........upgraded from 4.6  REdhat 5.0

got the src and rt of the autors VIM site via ftp.vim.org

changed the first requested by auther line in ".vimrc" file to not
read "version 4.00" and it worked once.....Gee

Now I am using it on everything ...DOS Win95 even NT40 !!!!

I know go back to the early version but still.....
what or why ...

"Segmentation Fault...Core dump"
thanks in advance.....Matt

2. History Screwed

3. Page Faults/Segmentation Faults??

4. pls help: inn problem

5. "Segmentation fault( core dumped ) "<--- sentence is driving me mad!!!!!

6. Spoof interview

7. segmentation fault ?

8. Mainboard with SCSI hostadapter

9. Get "Segmentation fault (core dumped)" but no core file found

10. Segmentation Faults and Bus Errors

11. Dosemu0.52 : Segmentation fault?

12. Segmentation fault on RH Linux 5.1

13. Segmentation fault