[OCLUG] Re: [OCLUG-devel] Trouble with strings and files

Christopher Smith x at xman.org
Wed Jul 7 23:14:15 PDT 2004


On Wed, 2004-07-07 at 22:11, Jack Denman wrote:
> On Tuesday 06 July 2004 10:19 pm, Christopher Smith wrote:
> > while (fgets(line, sizeof(line), in_file)) {
> >     FILE* target = div_file;
> >     int number = atoi(line);
> >     if ((number % 3) != 0) { /* != 0 is gratuitous, but clearer */
> >       target = other_file;
> >     }
> >     fputs(line, target);
> > }
> >
> > A number of advantages to this approach:
> >
> 
> fgets should not be used because of buffer overflow, a security violation and 
> the gcc compiler warns about that. The GNU way is as follows:

Wait... I think maybe I'm way too tired to be reading e-mail right now.
The code above uses *fgets*, not *gets* (and manages to use it properly
too!). How do you see a buffer overflow occurring?

-- 
Christopher Smith <x at xman.org>


More information about the OCLUG-devel mailing list