[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] Stack problems with GCC 4



On Mon, 24 Dec 2007 21:43:14 -0600
josephus <dogbird@earthlink.net> wrote:

> I have a K&R reference that says before you can put
> data into a pointer you must malloc that pointer.  I  am opening a
> passed in file name.   I started with
>   FILE * ptr;
> 
>   but I got a sigerr when I opened the file.  to fix the sig err I 
> malloced the pointer ptr.  the sig err went away.

fopen will normally take care of allocating the memory for the FILE*,
you don't have to do that manually. So unless you've screwed up the
parameters for fopen, there really should be no segmentation fault or
something similar there.

> sigerrs are the most useless linux error. it tells you nothing.

Well, it tells you that your program did something stupid, e.g. it
accessed memory that is not part of it's address space. You can use
tools like "catchsegv" and "gdb" to debug such problems.

> I sometimes get spontaneous sigerrs.  some I can fix and some I
> cannot. it works now,  wait and hold your mouth right and it will
> fail. no changes in environment.  so I end up trying to make it work.

Sounds like you're programming with a lot of dangling or illegal
pointers. You should make sure to initialize all unused pointer
variables to NULL, and also set pointer variables to NULL after you've
free()ed the memory again.

 Thomas