From f5e7e95921847bd83186bfe621fc2b48c4de5477 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 30 Oct 2018 13:11:47 +0100 Subject: stdlib/test-bz22786: Avoid spurious test failures using alias mappings On systems without enough random-access memory, stdlib/test-bz22786 will go deeply into swap and time out, even with a substantial TIMEOUTFACTOR. This commit adds a facility to construct repeating strings with alias mappings, so that the requirement for physical memory, and uses it in stdlib/test-bz22786. --- stdlib/test-bz22786.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'stdlib') diff --git a/stdlib/test-bz22786.c b/stdlib/test-bz22786.c index 777bf9180f..bb1e04f2de 100644 --- a/stdlib/test-bz22786.c +++ b/stdlib/test-bz22786.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -39,17 +40,12 @@ do_test (void) const char *lnk = xasprintf ("%s/symlink", dir); const size_t path_len = (size_t) INT_MAX + strlen (lnk) + 1; - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 7 warns about too-large allocations; here we need such - allocation to succeed for the test to work. */ - DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than="); -#endif - char *path = malloc (path_len); - DIAG_POP_NEEDS_COMMENT; + struct support_blob_repeat repeat + = support_blob_repeat_allocate ("a", 1, path_len); + char *path = repeat.start; if (path == NULL) { - printf ("malloc (%zu): %m\n", path_len); + printf ("Repeated allocation (%zu bytes): %m\n", path_len); /* On 31-bit s390 the malloc will always fail as we do not have so much memory, and we want to mark the test unsupported. Likewise on systems with little physical memory the test will @@ -62,7 +58,6 @@ do_test (void) /* Construct very long path = "/tmp/bz22786.XXXX/symlink/aaaa....." */ char *p = mempcpy (path, lnk, strlen (lnk)); *(p++) = '/'; - memset (p, 'a', path_len - (p - path) - 2); p[path_len - (p - path) - 1] = '\0'; /* This call crashes before the fix for bz22786 on 32-bit platforms. */ @@ -76,6 +71,7 @@ do_test (void) /* Cleanup. */ unlink (lnk); + support_blob_repeat_free (&repeat); return 0; } -- cgit v1.2.3 From 07da99aad93c9364acb7efdab47c27ba698f6313 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 30 Oct 2018 13:55:01 +0100 Subject: stdlib/tst-strtod-overflow: Switch to support_blob_repeat This is another test with an avoidable large memory allocation. --- stdlib/tst-strtod-overflow.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'stdlib') diff --git a/stdlib/tst-strtod-overflow.c b/stdlib/tst-strtod-overflow.c index d14638d68e..dc53c1e521 100644 --- a/stdlib/tst-strtod-overflow.c +++ b/stdlib/tst-strtod-overflow.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #define EXPONENT "e-2147483649" #define SIZE 214748364 @@ -26,21 +28,23 @@ static int do_test (void) { - char *p = malloc (1 + SIZE + sizeof (EXPONENT)); - if (p == NULL) + struct support_blob_repeat repeat = support_blob_repeat_allocate + ("0", 1, 1 + SIZE + sizeof (EXPONENT)); + if (repeat.size == 0) { - puts ("malloc failed, cannot test for overflow"); - return 0; + puts ("warning: memory allocation failed, cannot test for overflow"); + return EXIT_UNSUPPORTED; } + char *p = repeat.start; p[0] = '1'; - memset (p + 1, '0', SIZE); memcpy (p + 1 + SIZE, EXPONENT, sizeof (EXPONENT)); double d = strtod (p, NULL); if (d != 0) { - printf ("strtod returned wrong value: %a\n", d); + printf ("error: strtod returned wrong value: %a\n", d); return 1; } + support_blob_repeat_free (&repeat); return 0; } -- cgit v1.2.3 From 60708030536df82616c16aa2f14f533c4362b969 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 30 Oct 2018 13:56:40 +0100 Subject: stdlib/test-bz22786: Avoid memory leaks in the test itself --- stdlib/test-bz22786.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'stdlib') diff --git a/stdlib/test-bz22786.c b/stdlib/test-bz22786.c index bb1e04f2de..8035e8a394 100644 --- a/stdlib/test-bz22786.c +++ b/stdlib/test-bz22786.c @@ -36,8 +36,8 @@ static int do_test (void) { - const char *dir = support_create_temp_directory ("bz22786."); - const char *lnk = xasprintf ("%s/symlink", dir); + char *dir = support_create_temp_directory ("bz22786."); + char *lnk = xasprintf ("%s/symlink", dir); const size_t path_len = (size_t) INT_MAX + strlen (lnk) + 1; struct support_blob_repeat repeat @@ -72,6 +72,8 @@ do_test (void) /* Cleanup. */ unlink (lnk); support_blob_repeat_free (&repeat); + free (lnk); + free (dir); return 0; } -- cgit v1.2.3