[patch v1] stdio: Add more setvbuf tests
DJ Delorie
dj@redhat.com
Thu Mar 27 19:16:53 GMT 2025
Joseph Myers <josmyers@redhat.com> writes:
>> +#include <dlfcn.h>
>
> What's <dlfcn.h> used for in this test?
Probably excess from cut-n-paste'ing headers and copyright from another
test. Removed.
>> +/* Dear future developer: If you are reading this, you are likely
>> + trying to change or understand this test. In that case, these
>> + debug/dump macros will be helpful. */
>> +#if 0
>> +#define debug printf ("\033[3%dm%s:%d\033[0m\n", \
>
> Note the glibc style to use spaces after "#" for preprocessor directives
> inside #if, so "# define" here.
Fixed.
>> +void
>> +prepare_test_data (void)
>> +{
>> + buffer = (char *) malloc (bufsize);
>
> I'd expect a check for allocation failure (possibly through use of
> xmalloc). Maybe the code works even if allocation fails, but calling
> setvbuf with a NULL buffer probably isn't testing the intended paths.
Fixed.
>> + if (mknod (test_file_name, S_IFIFO | 0600, 0) != 0)
>> + FAIL_EXIT1 ("mknod: %m");
>
> This could use xmkfifo to avoid needing a local error check here.
Done.
>> + switch (s)
>> + {
>> + case test_stream_stdin:
>> + fp = fopen (fname, "r");
>> + break;
>
> In this code, you're consistently not checking for a null fp until later:
>
> In particular, the above uses fileno (fp) before the check for not being
> NULL.
>
> If interfaces such as xfopen can be used above, that would be the simplest
> way to get early-enough error checks.
I switched to xfopen, but we don't have a corresponding xfdopen, so I
left the TEST_VERIFY_EXIT in. I did move it before the ptmx code
though.
>> + if (s <= test_stream_stderr)
>> + {
>> + rv += recurse (fp, f, s, c);
>> + }
>> + else
>> + {
>> + rv += do_second_part (fp, f, s, c);
>> + }
>
> The normal style in glibc would be not to have braces around a single
> expression statement like this.
Fixed.
V2 will be sent in a moment...
More information about the Libc-alpha
mailing list