[PATCH v4] libio: null terminate the buffer upon initial allocation in getdelim
Collin Funk
collin.funk1@gmail.com
Sat Dec 6 04:48:59 GMT 2025
Eric Blake <eblake@redhat.com> writes:
>> + /* Test the same thing without a newline. */
>> + TEST_VERIFY_EXIT (fwrite ("d", 1, 1, fp) == 1);
>> + TEST_VERIFY_EXIT (fseeko (fp, -1, SEEK_CUR) == 0);
>> + TEST_VERIFY (getdelim (&lineptr, &linelen, '\n', fp) == 1);
>> + TEST_VERIFY (linelen > 2);
>
> On my first read, I wondered why this wasn't 'linelen > 1'. But on
> further thought, glibc guarantees that if the input size was already
> large enough, we don't realloc() to something smaller. So this line
> is correct for glibc behavior, even if it is stricter than what POSIX
> guarantees (and after all, several aspects of this unit test are about
> glibc behavior not regressing, even while providing guarantees not
> mandated by POSIX).
Interesting, I guess that behavior is allowed by POSIX. I think it would
be a bit strange to allocate a large buffer and then have getline
decrease the size, though.
> I don't know if my review counts since I'm not a regular contributor,
> but:
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
I think it should be fine.
Aside from that, it is best not to wait until a day before the release
to revert the problematic behavior of the previous change. Therefore, I
pushed this one.
Thanks again for your help clarifying this with POSIX.
Collin
More information about the Libc-alpha
mailing list