Date: Wed, 21 Mar 2012 22:39:45 +0700 From: Erich Dollansky <erichfreebsdlist@ovitrap.com> To: freebsd-questions@freebsd.org Cc: Martin McCormick <martin@dc.cis.okstate.edu> Subject: Re: Freebsd9.0 and the fgets directive in gcc Message-ID: <201203212239.45479.erichfreebsdlist@ovitrap.com> In-Reply-To: <201203211450.q2LEoPqM078354@dc.cis.okstate.edu> References: <201203211450.q2LEoPqM078354@dc.cis.okstate.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi,
On Wednesday 21 March 2012 21:50:25 Martin McCormick wrote:
> 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)) {
how long is one line? Could it be that the failing line has 256 or more characters?
I would use
while ( fgets(string0,sizeof(string0) -1,fp_config)) {
to make sure that the last character does not cause a buffer overrun, no matter what fgets is supposed to do.
Erich
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203212239.45479.erichfreebsdlist>
