Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Mar 2012 10:33:16 -0500
From:      Martin McCormick <martin@dc.cis.okstate.edu>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Freebsd9.0 and the fgets directive in gcc 
Message-ID:  <201203211533.q2LFXGdV006762@x.it.okstate.edu>

next in thread | raw e-mail | index | archive | help
Never mind. I may be back with another question, but I figured
out that it is not the input loop. I simply removed all the code
in the loop except for a variable that counts the number of
iterations and just ran thatand it read the entire file so the
problem is introduced when assigning values to variables based
on the contents of the lines. It is something that worked okay
up to FreeBSD8.X but now causes a segmentation fault.
Martin McCormick writes:
> I've got some code which I wrote about 6 or 8 years ago that
> apparently doesn't get along right now with FreeBSD9.0. In the
> problem code, there is a loop that uses fgets to read a line
> from a file. It runs properly until the 2708TH iteration and
> then it dumps core with a segmentation fault.
> 
> char string0[256];
> more lines of code . . .
> 
> while ( fgets(string0,sizeof(string0),fp_config)) {
> code to be run for each line
> }
> 
>         It runs fine until the 2,709TH iteration. Instead of
> reading the next line, it jumps to the line that closes
> fp_config even though it is far from read and exits with the
> segmentation fault.
> 
>         The man page on fgets says that if errors occur while
> running fgets, one must use perr to see whether the error
> terminated activity or it was the end of the file. In this case,
> it is definitely the error.
> 
>         Some observations:
> 
> The crash occurs on the 2,709TH input no matter how long I
> declared string0 to be. string0 is over-written each new
> iteration so nothing should be accumulating that uses up
> resources.
> 
>         Maybe I am declaring string0 in the wrong data type.
> Originally, it had been 1024 characters long but 2709 seems to
> be the C equivalent to the apocalypse and I thought it was
> supposed to be next December:-)
> 
>         This same code, by the way, also fails at about the same
> number of iterations if one uses fgetc and  builds the line one
> char at a time.
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to 
> "freebsd-questions-unsubscribe@freebsd.org"
> 
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203211533.q2LFXGdV006762>