[PATCH] libio: null terminate the buffer upon initial allocation in getdelim

Collin Funk collin.funk1@gmail.com
Thu Nov 27 20:23:15 GMT 2025


Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> writes:

>> -  /* Test that getdelim NUL terminates upon reading an EOF from an empty
>> -     file (BZ #28038).  This test fails on glibc 2.42 and earlier.  */
>> -  lineptr = xmalloc (1);
>> -  lineptr[0] = 'A';
>> -  linelen = 1;
>> +  /* Test that we null-terminate the buffer upon allocating it (BZ #28038).  */
>> +  lineptr = NULL;
>> +  linelen = 0;
>>    char *file_name;
>>    TEST_VERIFY_EXIT (create_temp_file ("tst-getdelim.", &file_name) != -1);
>>    FILE *fp = fopen (file_name, "r");
>
> This tests with an empty file, should we also check with non-empty file to
> ensure that getline returns the last line from the file?

Good point. Let me write a v2 to add a test case for that, so we (or I,
most likely) don't break it in the future.

Collin


More information about the Libc-alpha mailing list