diff options
Diffstat (limited to 'stdlib/tst-strtod-overflow.c')
-rw-r--r-- | stdlib/tst-strtod-overflow.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/stdlib/tst-strtod-overflow.c b/stdlib/tst-strtod-overflow.c index d14638d68e..a99b43f4d9 100644 --- a/stdlib/tst-strtod-overflow.c +++ b/stdlib/tst-strtod-overflow.c @@ -1,5 +1,5 @@ /* Test for integer/buffer overflow in strtod. - Copyright (C) 2012-2018 Free Software Foundation, Inc. + Copyright (C) 2012-2019 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 @@ -14,11 +14,13 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ + <https://www.gnu.org/licenses/>. */ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <support/blob_repeat.h> +#include <support/test-driver.h> #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; } |