Message ID | 20240814081625.453536-1-fberat@redhat.com |
---|---|
State | New |
Headers | show |
Series | libio/tst-getdelim: Add new test covering NUL as a delimiter | expand |
On Aug 14 2024, Frédéric Bérat wrote: > + /* Test getdelim with NUL as delimiter */ > + verbose_printf ("Testing NUL delimiter\n"); Please use null byte or null character instead of the abbreviation.
On Wed, Aug 14, 2024 at 11:51 AM Andreas Schwab <schwab@suse.de> wrote: > On Aug 14 2024, Frédéric Bérat wrote: > > > + /* Test getdelim with NUL as delimiter */ > > + verbose_printf ("Testing NUL delimiter\n"); > > Please use null byte or null character instead of the abbreviation. > Well, that's unfortunate. I've sent a follow-up. > > -- > Andreas Schwab, SUSE Labs, schwab@suse.de > GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 > "And now for something completely different." > >
On Wed, 14 Aug 2024, Frederic Berat wrote: > > > + /* Test getdelim with NUL as delimiter */ > > > + verbose_printf ("Testing NUL delimiter\n"); > > > > Please use null byte or null character instead of the abbreviation. > > > > Well, that's unfortunate. I've sent a follow-up. Which is also why I always wait at least ~48h once my changes have been reviewed/approved before pushing them, to allow for late input or insight. There's no need to rush changes in, nothing should be done in haste but gripping a flea. Maciej
diff --git a/libio/tst-getdelim.c b/libio/tst-getdelim.c index e6dd964b49..709996c204 100644 --- a/libio/tst-getdelim.c +++ b/libio/tst-getdelim.c @@ -1,4 +1,6 @@ -/* Check that getdelim sets error indicator on error (BZ #29917) +/* Test getdelim conforming to POSIX specifications. + + Note: Most getdelim use cases are covered by stdio-common/tst-getline. Copyright (C) 2023-2024 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -18,18 +20,36 @@ <https://www.gnu.org/licenses/>. */ #include <stdio.h> +#include <stdlib.h> #include <errno.h> #include <support/check.h> +#include <support/support.h> +#include <support/test-driver.h> static int do_test (void) { + /* Check that getdelim sets error indicator on error (BZ #29917) */ clearerr (stdin); TEST_VERIFY (getdelim (0, 0, '\n', stdin) == -1); TEST_VERIFY (ferror (stdin) != 0); TEST_VERIFY (errno == EINVAL); + /* Test getdelim with NUL as delimiter */ + verbose_printf ("Testing NUL delimiter\n"); + char *lineptr = NULL; + size_t linelen = 0; + char membuf[] = "abc\0d\nef\0"; + FILE *memstream = fmemopen(membuf, sizeof(membuf), "r"); + TEST_VERIFY_EXIT (memstream != NULL); + TEST_VERIFY (getdelim (&lineptr, &linelen, '\0', memstream) != -1); + TEST_COMPARE_BLOB (lineptr, 4, "abc\0", 4); + TEST_VERIFY (getdelim (&lineptr, &linelen, '\0', memstream) != -1); + TEST_COMPARE_BLOB (lineptr, 5, "d\nef\0", 5); + fclose (memstream); + free (lineptr); + return 0; }