From b9125aeaed45e10ce329f91f007eb3da43d2155f Mon Sep 17 00:00:00 2001 From: Carlos O'Donell Date: Wed, 17 May 2023 09:33:05 -0400 Subject: stdio-common: Adjust tests in Makefile Sort tests against updated scripts/sort-makefile-lines.py. No changes in generated code. No regressions on x86_64 and i686. Reviewed-by: Siddhesh Poyarekar --- stdio-common/Makefile | 44 ++++++------- stdio-common/bug23-2.c | 70 -------------------- stdio-common/bug23-3.c | 50 -------------- stdio-common/bug23-4.c | 31 --------- stdio-common/bug27.c | 70 ++++++++++++++++++++ stdio-common/bug28.c | 50 ++++++++++++++ stdio-common/bug29.c | 31 +++++++++ stdio-common/scanf14a.c | 141 --------------------------------------- stdio-common/scanf16a.c | 171 ------------------------------------------------ stdio-common/scanf18.c | 141 +++++++++++++++++++++++++++++++++++++++ stdio-common/scanf19.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 485 insertions(+), 485 deletions(-) delete mode 100644 stdio-common/bug23-2.c delete mode 100644 stdio-common/bug23-3.c delete mode 100644 stdio-common/bug23-4.c create mode 100644 stdio-common/bug27.c create mode 100644 stdio-common/bug28.c create mode 100644 stdio-common/bug29.c delete mode 100644 stdio-common/scanf14a.c delete mode 100644 stdio-common/scanf16a.c create mode 100644 stdio-common/scanf18.c create mode 100644 stdio-common/scanf19.c (limited to 'stdio-common') diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 1b4997afc8..4c15b97683 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -130,6 +130,13 @@ aux := \ tests := \ bug-vfprintf-nargs \ bug1 \ + bug3 \ + bug4 \ + bug5 \ + bug6 \ + bug7 \ + bug8 \ + bug9 \ bug10 \ bug11 \ bug12 \ @@ -146,38 +153,31 @@ tests := \ bug21 \ bug22 \ bug23 \ - bug23-2 \ - bug23-3 \ - bug23-4 \ bug24 \ bug25 \ bug26 \ - bug3 \ - bug4 \ - bug5 \ - bug6 \ - bug7 \ - bug8 \ - bug9 \ + bug27 \ + bug28 \ + bug29 \ errnobug \ scanf1 \ + scanf2 \ + scanf3 \ + scanf4 \ + scanf5 \ + scanf7 \ + scanf8 \ + scanf9 \ scanf10 \ scanf11 \ scanf12 \ scanf13 \ scanf14 \ - scanf14a \ scanf15 \ scanf16 \ - scanf16a \ scanf17 \ - scanf2 \ - scanf3 \ - scanf4 \ - scanf5 \ - scanf7 \ - scanf8 \ - scanf9 \ + scanf18 \ + scanf19 \ temptest \ test-fseek \ test-fwrite \ @@ -442,11 +442,11 @@ CFLAGS-isoc23_scanf.c += -fexceptions CFLAGS-dprintf.c += $(config-cflags-wno-ignored-attributes) -# scanf14a.c and scanf16a.c test a deprecated extension which is no +# scanf18.c and scanf19.c test a deprecated extension which is no # longer visible under most conformance levels; see the source files # for more detail. -CFLAGS-scanf14a.c += -std=gnu89 -CFLAGS-scanf16a.c += -std=gnu89 +CFLAGS-scanf18.c += -std=gnu89 +CFLAGS-scanf19.c += -std=gnu89 CFLAGS-bug3.c += -DOBJPFX=\"$(objpfx)\" CFLAGS-bug4.c += -DOBJPFX=\"$(objpfx)\" diff --git a/stdio-common/bug23-2.c b/stdio-common/bug23-2.c deleted file mode 100644 index 9e0cfe6860..0000000000 --- a/stdio-common/bug23-2.c +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include - -static const char expected[] = "\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55\ -\n\ -a\n\ -abbcd55%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; - -static int -do_test (void) -{ - char *buf = malloc (strlen (expected) + 1); - snprintf (buf, strlen (expected) + 1, - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", - "a", "b", "c", "d", 5); - return strcmp (buf, expected) != 0; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/stdio-common/bug23-3.c b/stdio-common/bug23-3.c deleted file mode 100644 index 57c8cef195..0000000000 --- a/stdio-common/bug23-3.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include - -int -do_test (void) -{ - size_t instances = 16384; -#define X0 "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" - const char *item = "\na\nabbcd55"; -#define X3 X0 X0 X0 X0 X0 X0 X0 X0 -#define X6 X3 X3 X3 X3 X3 X3 X3 X3 -#define X9 X6 X6 X6 X6 X6 X6 X6 X6 -#define X12 X9 X9 X9 X9 X9 X9 X9 X9 -#define X14 X12 X12 X12 X12 -#define TRAILER "%%%%%%%%%%%%%%%%%%%%%%%%%%" -#define TRAILER2 TRAILER TRAILER - size_t length = instances * strlen (item) + strlen (TRAILER) + 1; - - char *buf = malloc (length + 1); - snprintf (buf, length + 1, - X14 TRAILER2 "\n", - "a", "b", "c", "d", 5); - - const char *p = buf; - size_t i; - for (i = 0; i < instances; ++i) - { - const char *expected; - for (expected = item; *expected; ++expected) - { - if (*p != *expected) - { - printf ("mismatch at offset %zu (%zu): expected %d, got %d\n", - (size_t) (p - buf), i, *expected & 0xFF, *p & 0xFF); - return 1; - } - ++p; - } - } - if (strcmp (p, TRAILER "\n") != 0) - { - printf ("mismatch at trailer: [%s]\n", p); - return 1; - } - free (buf); - return 0; -} -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/stdio-common/bug23-4.c b/stdio-common/bug23-4.c deleted file mode 100644 index a4785640de..0000000000 --- a/stdio-common/bug23-4.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include - -#define LIMIT 1000000 - -int -main (void) -{ - struct rlimit lim; - getrlimit (RLIMIT_STACK, &lim); - lim.rlim_cur = 1048576; - setrlimit (RLIMIT_STACK, &lim); - char *fmtstr = malloc (4 * LIMIT + 1); - if (fmtstr == NULL) - abort (); - char *output = malloc (LIMIT + 1); - if (output == NULL) - abort (); - for (size_t i = 0; i < LIMIT; i++) - memcpy (fmtstr + 4 * i, "%1$d", 4); - fmtstr[4 * LIMIT] = '\0'; - int ret = snprintf (output, LIMIT + 1, fmtstr, 0); - if (ret != LIMIT) - abort (); - for (size_t i = 0; i < LIMIT; i++) - if (output[i] != '0') - abort (); - return 0; -} diff --git a/stdio-common/bug27.c b/stdio-common/bug27.c new file mode 100644 index 0000000000..9e0cfe6860 --- /dev/null +++ b/stdio-common/bug27.c @@ -0,0 +1,70 @@ +#include +#include +#include + +static const char expected[] = "\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55\ +\n\ +a\n\ +abbcd55%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; + +static int +do_test (void) +{ + char *buf = malloc (strlen (expected) + 1); + snprintf (buf, strlen (expected) + 1, + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", + "a", "b", "c", "d", 5); + return strcmp (buf, expected) != 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/bug28.c b/stdio-common/bug28.c new file mode 100644 index 0000000000..57c8cef195 --- /dev/null +++ b/stdio-common/bug28.c @@ -0,0 +1,50 @@ +#include +#include +#include + +int +do_test (void) +{ + size_t instances = 16384; +#define X0 "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d" + const char *item = "\na\nabbcd55"; +#define X3 X0 X0 X0 X0 X0 X0 X0 X0 +#define X6 X3 X3 X3 X3 X3 X3 X3 X3 +#define X9 X6 X6 X6 X6 X6 X6 X6 X6 +#define X12 X9 X9 X9 X9 X9 X9 X9 X9 +#define X14 X12 X12 X12 X12 +#define TRAILER "%%%%%%%%%%%%%%%%%%%%%%%%%%" +#define TRAILER2 TRAILER TRAILER + size_t length = instances * strlen (item) + strlen (TRAILER) + 1; + + char *buf = malloc (length + 1); + snprintf (buf, length + 1, + X14 TRAILER2 "\n", + "a", "b", "c", "d", 5); + + const char *p = buf; + size_t i; + for (i = 0; i < instances; ++i) + { + const char *expected; + for (expected = item; *expected; ++expected) + { + if (*p != *expected) + { + printf ("mismatch at offset %zu (%zu): expected %d, got %d\n", + (size_t) (p - buf), i, *expected & 0xFF, *p & 0xFF); + return 1; + } + ++p; + } + } + if (strcmp (p, TRAILER "\n") != 0) + { + printf ("mismatch at trailer: [%s]\n", p); + return 1; + } + free (buf); + return 0; +} +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/bug29.c b/stdio-common/bug29.c new file mode 100644 index 0000000000..a4785640de --- /dev/null +++ b/stdio-common/bug29.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#define LIMIT 1000000 + +int +main (void) +{ + struct rlimit lim; + getrlimit (RLIMIT_STACK, &lim); + lim.rlim_cur = 1048576; + setrlimit (RLIMIT_STACK, &lim); + char *fmtstr = malloc (4 * LIMIT + 1); + if (fmtstr == NULL) + abort (); + char *output = malloc (LIMIT + 1); + if (output == NULL) + abort (); + for (size_t i = 0; i < LIMIT; i++) + memcpy (fmtstr + 4 * i, "%1$d", 4); + fmtstr[4 * LIMIT] = '\0'; + int ret = snprintf (output, LIMIT + 1, fmtstr, 0); + if (ret != LIMIT) + abort (); + for (size_t i = 0; i < LIMIT; i++) + if (output[i] != '0') + abort (); + return 0; +} diff --git a/stdio-common/scanf14a.c b/stdio-common/scanf14a.c deleted file mode 100644 index 506431d96f..0000000000 --- a/stdio-common/scanf14a.c +++ /dev/null @@ -1,141 +0,0 @@ -/* Copyright (C) 2007-2023 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* This test exercises the deprecated GNU %as, %aS, and %a[...] scanf - modifiers, which are not available to programs compiled as C99 - anymore; therefore, this file is compiled with -std=gnu89 and C99 - syntax must not be used. */ - -#include -#include -#include -#include - -#if !__GLIBC_USE_DEPRECATED_SCANF -# error "This file should be compiled with deprecated scanf" -#endif - - -#define FAIL() \ - do { \ - result = 1; \ - printf ("test at line %d failed\n", __LINE__); \ - } while (0) - -int -main (void) -{ - wchar_t *lsp; - char *sp; - float f; - double d; - char c[8]; - int result = 0; - - if (sscanf (" 0.25s x", "%e%3c", &f, c) != 2) - FAIL (); - else if (f != 0.25 || memcmp (c, "s x", 3) != 0) - FAIL (); - if (sscanf (" 1.25s x", "%as%2c", &sp, c) != 2) - FAIL (); - else - { - if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) - FAIL (); - memset (sp, 'x', sizeof "1.25s"); - free (sp); - } - if (sscanf (" 2.25s x", "%las%2c", &d, c) != 2) - FAIL (); - else if (d != 2.25 || memcmp (c, " x", 2) != 0) - FAIL (); - if (sscanf (" 3.25S x", "%4aS%3c", &lsp, c) != 2) - FAIL (); - else - { - if (wcscmp (lsp, L"3.25") != 0 || memcmp (c, "S x", 3) != 0) - FAIL (); - memset (lsp, 'x', sizeof L"3.25"); - free (lsp); - } - if (sscanf ("4.25[0-9.] x", "%a[0-9.]%8c", &sp, c) != 2) - FAIL (); - else - { - if (strcmp (sp, "4.25") != 0 || memcmp (c, "[0-9.] x", 8) != 0) - FAIL (); - memset (sp, 'x', sizeof "4.25"); - free (sp); - } - if (sscanf ("5.25[0-9.] x", "%la[0-9.]%2c", &d, c) != 2) - FAIL (); - else if (d != 5.25 || memcmp (c, " x", 2) != 0) - FAIL (); - - const char *tmpdir = getenv ("TMPDIR"); - if (tmpdir == NULL || tmpdir[0] == '\0') - tmpdir = "/tmp"; - - char fname[strlen (tmpdir) + sizeof "/tst-scanf14.XXXXXX"]; - sprintf (fname, "%s/tst-scanf14.XXXXXX", tmpdir); - - /* Create a temporary file. */ - int fd = mkstemp (fname); - if (fd == -1) - FAIL (); - - FILE *fp = fdopen (fd, "w+"); - if (fp == NULL) - FAIL (); - else - { - if (fputs (" 1.25s x", fp) == EOF) - FAIL (); - if (fseek (fp, 0, SEEK_SET) != 0) - FAIL (); - if (fscanf (fp, "%as%2c", &sp, c) != 2) - FAIL (); - else - { - if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) - FAIL (); - memset (sp, 'x', sizeof "1.25s"); - free (sp); - } - - if (freopen (fname, "r", stdin) == NULL) - FAIL (); - else - { - if (scanf ("%as%2c", &sp, c) != 2) - FAIL (); - else - { - if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) - FAIL (); - memset (sp, 'x', sizeof "1.25s"); - free (sp); - } - } - - fclose (fp); - } - - remove (fname); - - return result; -} diff --git a/stdio-common/scanf16a.c b/stdio-common/scanf16a.c deleted file mode 100644 index 196dca2915..0000000000 --- a/stdio-common/scanf16a.c +++ /dev/null @@ -1,171 +0,0 @@ -/* Copyright (C) 2008-2023 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* This test exercises the deprecated GNU %as, %aS, and %a[...] scanf - modifiers, which are not available to programs compiled as C99 - anymore; therefore, this file is compiled with -std=gnu89 and C99 - syntax must not be used. */ - -#include -#include -#include -#include -#include - -#if !__GLIBC_USE_DEPRECATED_SCANF -# error "This file should be compiled with deprecated scanf" -#endif - -#define FAIL() \ - do { \ - result = 1; \ - printf ("test at line %d failed\n", __LINE__); \ - } while (0) - -static int __attribute__ ((format (scanf, 2, 3))) -xsscanf (const char *str, const char *fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - int ret = vsscanf (str, fmt, ap); - va_end (ap); - return ret; -} - -static int __attribute__ ((format (scanf, 1, 2))) -xscanf (const char *fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - int ret = vscanf (fmt, ap); - va_end (ap); - return ret; -} - -static int __attribute__ ((format (scanf, 2, 3))) -xfscanf (FILE *f, const char *fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - int ret = vfscanf (f, fmt, ap); - va_end (ap); - return ret; -} - -int -main (void) -{ - wchar_t *lsp; - char *sp; - float f; - double d; - char c[8]; - int result = 0; - - if (xsscanf (" 0.25s x", "%e%3c", &f, c) != 2) - FAIL (); - else if (f != 0.25 || memcmp (c, "s x", 3) != 0) - FAIL (); - if (xsscanf (" 1.25s x", "%as%2c", &sp, c) != 2) - FAIL (); - else - { - if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) - FAIL (); - memset (sp, 'x', sizeof "1.25s"); - free (sp); - } - if (xsscanf (" 2.25s x", "%las%2c", &d, c) != 2) - FAIL (); - else if (d != 2.25 || memcmp (c, " x", 2) != 0) - FAIL (); - if (xsscanf (" 3.25S x", "%4aS%3c", &lsp, c) != 2) - FAIL (); - else - { - if (wcscmp (lsp, L"3.25") != 0 || memcmp (c, "S x", 3) != 0) - FAIL (); - memset (lsp, 'x', sizeof L"3.25"); - free (lsp); - } - if (xsscanf ("4.25[0-9.] x", "%a[0-9.]%8c", &sp, c) != 2) - FAIL (); - else - { - if (strcmp (sp, "4.25") != 0 || memcmp (c, "[0-9.] x", 8) != 0) - FAIL (); - memset (sp, 'x', sizeof "4.25"); - free (sp); - } - if (xsscanf ("5.25[0-9.] x", "%la[0-9.]%2c", &d, c) != 2) - FAIL (); - else if (d != 5.25 || memcmp (c, " x", 2) != 0) - FAIL (); - - const char *tmpdir = getenv ("TMPDIR"); - if (tmpdir == NULL || tmpdir[0] == '\0') - tmpdir = "/tmp"; - - char fname[strlen (tmpdir) + sizeof "/tst-scanf16.XXXXXX"]; - sprintf (fname, "%s/tst-scanf16.XXXXXX", tmpdir); - - /* Create a temporary file. */ - int fd = mkstemp (fname); - if (fd == -1) - FAIL (); - - FILE *fp = fdopen (fd, "w+"); - if (fp == NULL) - FAIL (); - else - { - if (fputs (" 1.25s x", fp) == EOF) - FAIL (); - if (fseek (fp, 0, SEEK_SET) != 0) - FAIL (); - if (xfscanf (fp, "%as%2c", &sp, c) != 2) - FAIL (); - else - { - if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) - FAIL (); - memset (sp, 'x', sizeof "1.25s"); - free (sp); - } - - if (freopen (fname, "r", stdin) == NULL) - FAIL (); - else - { - if (xscanf ("%as%2c", &sp, c) != 2) - FAIL (); - else - { - if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) - FAIL (); - memset (sp, 'x', sizeof "1.25s"); - free (sp); - } - } - - fclose (fp); - } - - remove (fname); - - return result; -} diff --git a/stdio-common/scanf18.c b/stdio-common/scanf18.c new file mode 100644 index 0000000000..506431d96f --- /dev/null +++ b/stdio-common/scanf18.c @@ -0,0 +1,141 @@ +/* Copyright (C) 2007-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This test exercises the deprecated GNU %as, %aS, and %a[...] scanf + modifiers, which are not available to programs compiled as C99 + anymore; therefore, this file is compiled with -std=gnu89 and C99 + syntax must not be used. */ + +#include +#include +#include +#include + +#if !__GLIBC_USE_DEPRECATED_SCANF +# error "This file should be compiled with deprecated scanf" +#endif + + +#define FAIL() \ + do { \ + result = 1; \ + printf ("test at line %d failed\n", __LINE__); \ + } while (0) + +int +main (void) +{ + wchar_t *lsp; + char *sp; + float f; + double d; + char c[8]; + int result = 0; + + if (sscanf (" 0.25s x", "%e%3c", &f, c) != 2) + FAIL (); + else if (f != 0.25 || memcmp (c, "s x", 3) != 0) + FAIL (); + if (sscanf (" 1.25s x", "%as%2c", &sp, c) != 2) + FAIL (); + else + { + if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) + FAIL (); + memset (sp, 'x', sizeof "1.25s"); + free (sp); + } + if (sscanf (" 2.25s x", "%las%2c", &d, c) != 2) + FAIL (); + else if (d != 2.25 || memcmp (c, " x", 2) != 0) + FAIL (); + if (sscanf (" 3.25S x", "%4aS%3c", &lsp, c) != 2) + FAIL (); + else + { + if (wcscmp (lsp, L"3.25") != 0 || memcmp (c, "S x", 3) != 0) + FAIL (); + memset (lsp, 'x', sizeof L"3.25"); + free (lsp); + } + if (sscanf ("4.25[0-9.] x", "%a[0-9.]%8c", &sp, c) != 2) + FAIL (); + else + { + if (strcmp (sp, "4.25") != 0 || memcmp (c, "[0-9.] x", 8) != 0) + FAIL (); + memset (sp, 'x', sizeof "4.25"); + free (sp); + } + if (sscanf ("5.25[0-9.] x", "%la[0-9.]%2c", &d, c) != 2) + FAIL (); + else if (d != 5.25 || memcmp (c, " x", 2) != 0) + FAIL (); + + const char *tmpdir = getenv ("TMPDIR"); + if (tmpdir == NULL || tmpdir[0] == '\0') + tmpdir = "/tmp"; + + char fname[strlen (tmpdir) + sizeof "/tst-scanf14.XXXXXX"]; + sprintf (fname, "%s/tst-scanf14.XXXXXX", tmpdir); + + /* Create a temporary file. */ + int fd = mkstemp (fname); + if (fd == -1) + FAIL (); + + FILE *fp = fdopen (fd, "w+"); + if (fp == NULL) + FAIL (); + else + { + if (fputs (" 1.25s x", fp) == EOF) + FAIL (); + if (fseek (fp, 0, SEEK_SET) != 0) + FAIL (); + if (fscanf (fp, "%as%2c", &sp, c) != 2) + FAIL (); + else + { + if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) + FAIL (); + memset (sp, 'x', sizeof "1.25s"); + free (sp); + } + + if (freopen (fname, "r", stdin) == NULL) + FAIL (); + else + { + if (scanf ("%as%2c", &sp, c) != 2) + FAIL (); + else + { + if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) + FAIL (); + memset (sp, 'x', sizeof "1.25s"); + free (sp); + } + } + + fclose (fp); + } + + remove (fname); + + return result; +} diff --git a/stdio-common/scanf19.c b/stdio-common/scanf19.c new file mode 100644 index 0000000000..196dca2915 --- /dev/null +++ b/stdio-common/scanf19.c @@ -0,0 +1,171 @@ +/* Copyright (C) 2008-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This test exercises the deprecated GNU %as, %aS, and %a[...] scanf + modifiers, which are not available to programs compiled as C99 + anymore; therefore, this file is compiled with -std=gnu89 and C99 + syntax must not be used. */ + +#include +#include +#include +#include +#include + +#if !__GLIBC_USE_DEPRECATED_SCANF +# error "This file should be compiled with deprecated scanf" +#endif + +#define FAIL() \ + do { \ + result = 1; \ + printf ("test at line %d failed\n", __LINE__); \ + } while (0) + +static int __attribute__ ((format (scanf, 2, 3))) +xsscanf (const char *str, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + int ret = vsscanf (str, fmt, ap); + va_end (ap); + return ret; +} + +static int __attribute__ ((format (scanf, 1, 2))) +xscanf (const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + int ret = vscanf (fmt, ap); + va_end (ap); + return ret; +} + +static int __attribute__ ((format (scanf, 2, 3))) +xfscanf (FILE *f, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + int ret = vfscanf (f, fmt, ap); + va_end (ap); + return ret; +} + +int +main (void) +{ + wchar_t *lsp; + char *sp; + float f; + double d; + char c[8]; + int result = 0; + + if (xsscanf (" 0.25s x", "%e%3c", &f, c) != 2) + FAIL (); + else if (f != 0.25 || memcmp (c, "s x", 3) != 0) + FAIL (); + if (xsscanf (" 1.25s x", "%as%2c", &sp, c) != 2) + FAIL (); + else + { + if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) + FAIL (); + memset (sp, 'x', sizeof "1.25s"); + free (sp); + } + if (xsscanf (" 2.25s x", "%las%2c", &d, c) != 2) + FAIL (); + else if (d != 2.25 || memcmp (c, " x", 2) != 0) + FAIL (); + if (xsscanf (" 3.25S x", "%4aS%3c", &lsp, c) != 2) + FAIL (); + else + { + if (wcscmp (lsp, L"3.25") != 0 || memcmp (c, "S x", 3) != 0) + FAIL (); + memset (lsp, 'x', sizeof L"3.25"); + free (lsp); + } + if (xsscanf ("4.25[0-9.] x", "%a[0-9.]%8c", &sp, c) != 2) + FAIL (); + else + { + if (strcmp (sp, "4.25") != 0 || memcmp (c, "[0-9.] x", 8) != 0) + FAIL (); + memset (sp, 'x', sizeof "4.25"); + free (sp); + } + if (xsscanf ("5.25[0-9.] x", "%la[0-9.]%2c", &d, c) != 2) + FAIL (); + else if (d != 5.25 || memcmp (c, " x", 2) != 0) + FAIL (); + + const char *tmpdir = getenv ("TMPDIR"); + if (tmpdir == NULL || tmpdir[0] == '\0') + tmpdir = "/tmp"; + + char fname[strlen (tmpdir) + sizeof "/tst-scanf16.XXXXXX"]; + sprintf (fname, "%s/tst-scanf16.XXXXXX", tmpdir); + + /* Create a temporary file. */ + int fd = mkstemp (fname); + if (fd == -1) + FAIL (); + + FILE *fp = fdopen (fd, "w+"); + if (fp == NULL) + FAIL (); + else + { + if (fputs (" 1.25s x", fp) == EOF) + FAIL (); + if (fseek (fp, 0, SEEK_SET) != 0) + FAIL (); + if (xfscanf (fp, "%as%2c", &sp, c) != 2) + FAIL (); + else + { + if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) + FAIL (); + memset (sp, 'x', sizeof "1.25s"); + free (sp); + } + + if (freopen (fname, "r", stdin) == NULL) + FAIL (); + else + { + if (xscanf ("%as%2c", &sp, c) != 2) + FAIL (); + else + { + if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0) + FAIL (); + memset (sp, 'x', sizeof "1.25s"); + free (sp); + } + } + + fclose (fp); + } + + remove (fname); + + return result; +} -- cgit 1.4.1