On Mon, 14 Feb 2000 11:43:25 -0800, "davidturetsky" <[EMAIL PROTECTED]> was
crying out from somewhere
about: Re: Segmentation fault
davidturetsky> I believe this is the code that was getting me into trouble, but
it could be
davidturetsky> elsewhere
davidturetsky>
davidturetsky> fscanf (file, "%s", Title);
davidturetsky> fscanf (file, "%d %d %d %d %d %d", &m, &n, &it, <, &EQ,
>);
Probably, the input string was too long for the char* Title?
I don't know. MSC seems to let the stack be destroyed quite quietly.
It's a feature, methinks. Not too many segfaults when developing, but
occasional BOD on using.
davidturetsky> Thanks, dancer. BTW, what's wrong with your code sample? I can
see this is
davidturetsky> going to be daunting!
davidturetsky> > For example, this code segfaults on Linux, which used to work
perfectly
davidturetsky> fine on MSC:
davidturetsky> >
davidturetsky> > char * bitsofmemory = malloc (BIG_SIZE); FILE*f
=fopen(FILENAME,
davidturetsky> ATTRIBUTE);
davidturetsky> > if (!(bitsofmemory && f)) {
davidturetsky> > free(bitsofmemory); fclose(f) /* try to clean up and it
dies...*/
davidturetsky> > return ERROR;
davidturetsky> > }
It it meant to free up the allocated memory space and the file handle when
either operation
fails (a kind of expression found at the beginning of many functions). But one
is trying to
free up a NULL pointer, and that probably means read/write to a
location where it is probably (or hopefully) not allocated to the program.
Either the MS library checks for NULL every time it is called (I think that's
kinda nice, but
then, it is a waste), or NULL might be a place you can dump things on.
One thing. To make it run on Linux, I had to change it to:
davidturetsky> > if (!(bitsofmemory && f)) {
davidturetsky> > if (bitsofmemory)free(bitsofmemory); if(f)fclose(f) /* try
to clean up and it dies...*/
davidturetsky> > return ERROR;
davidturetsky> > }
---------------------------------------------------------------------------
dancer, a.k.a. Junichi Uekawa
a member of the Dept. of Knowledge Engineering and Computer Science,
Doshisha University.
... I pronounce "Linux" as in [Day-bee-enne]