This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
getline() and size_t
- From: Michael Vaughn <mvaughn at wisc dot edu>
- To: libc-help at sourceware dot org
- Date: Tue, 04 May 2010 12:53:20 -0500
- Subject: getline() and size_t
Hello,
I have an odd and somewhat dumb question. While using getline() for the first time, (with a pointer to NULL for lineptr), I accidentally passed int * instead of size_t* for the second argument. What was surprising to me is that this somehow causes corruption of the allocated heap data. When I go to free the buffer, I get the classic "double free or corruption" message and dump.
I'm not entirely certain how the type mix-up could cause such wide-ranging issues when getline() goes to allocate the buffer, (especially considering I was using a positive 4-bit integer, and size_t is 8 bits so I wouldn't expect there to be, for example, a sign extension issue.)
Obviously, using int * is wrong, but I was wondering if anyone could clarify what goes on when I mix up size_t and int in this context. [For my peace of mind - something about a memory corruption issue that I don't fully understand, even if it is seemingly rectified worries me].
Thank you for your patience,
Michael Vaughn