[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getline() bug
From: |
John V. Shahid |
Subject: |
Re: getline() bug |
Date: |
Thu, 26 Jul 2007 13:09:46 -0400 |
Thanks a lot for pointing that out.
I just wanted to point out to the fact that the MACRO that need to be
defined (GNU_SOURCE) isn't mentioned in the info pages of libc. Or at
least in the getline and getdelim section. I've been using getline for a
while and always had the warning about the implicit declaration but
thought it's kind of bug since I always include the mentioned header
files. Do you think I should send this to the current maintainers of the
info pages of libc ?
On Wed, 2007-07-25 at 13:36 -0700, Paul Pluzhnikov wrote:
> "John V. Shahid" <jvshahid@gmail.com> writes:
>
> > I think I found a bug in getline().
>
> Nope. The bug is in your program (but I'll grant you -- it's an
> obscure one).
>
> Compile your code with -Wall, and you'll see this:
>
> $ gcc -Wall junk3.c
> junk3.c: In function 'main':
> junk3.c:19: warning: implicit declaration of function 'getline'
> junk3.c:7: warning: unused variable 'count'
>
> The 'man getline' tells you to do this:
> #define _GNU_SOURCE
>
> Adding that to junk3.c, and compiling again with -Wall, tells you
> the root of the problem:
>
> junk3.c: In function 'main':
> junk3.c:20: warning: passing argument 2 of 'getline' from incompatible
> pointer type
>
> Fixing that problem:
>
> // int lineSize, count;
> size_t lineSize;
>
> cures the warning, cures your bug, and makes valgrind happy:
>
> ==28863== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 1)
>
> Cheers,