ppc: Fix modf (sNaN) for pre-POWER5+ CPU (bug 20240).
[glibc.git] / stdio-common / tst-vfprintf-width-prec.c
blob28927419ee492139b6bdd355232aa2d190153609
1 /* Test for memory leak with large width and precision.
2 Copyright (C) 1991-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <mcheck.h>
20 #include <stdio.h>
21 #include <sys/resource.h>
22 #include <wchar.h>
24 static int
25 do_test (void)
27 mtrace ();
29 int ret;
31 char *result;
32 ret = asprintf (&result, "%133000.133001x", 17);
33 if (ret < 0)
35 printf ("error: asprintf: %m\n");
36 return 1;
38 free (result);
41 wchar_t *result = calloc (ret + 1, sizeof (wchar_t));
42 if (result == NULL)
44 printf ("error: calloc (%d, %zu): %m", ret + 1, sizeof (wchar_t));
45 return 1;
48 ret = swprintf (result, ret + 1, L"%133000.133001x", 17);
49 if (ret < 0)
51 printf ("error: swprintf: %d (%m)\n", ret);
52 return 1;
54 free (result);
57 /* Limit the size of the process, so that the second allocation will
58 fail. */
60 struct rlimit limit;
61 if (getrlimit (RLIMIT_AS, &limit) != 0)
63 printf ("getrlimit (RLIMIT_AS) failed: %m\n");
64 return 1;
66 long target = 200 * 1024 * 1024;
67 if (limit.rlim_cur == RLIM_INFINITY || limit.rlim_cur > target)
69 limit.rlim_cur = target;
70 if (setrlimit (RLIMIT_AS, &limit) != 0)
72 printf ("setrlimit (RLIMIT_AS) failed: %m\n");
73 return 1;
79 char *result;
80 ret = asprintf (&result, "%133000.999999999x", 17);
81 if (ret >= 0)
83 printf ("error: asprintf: incorrect result %d\n", ret);
84 return 1;
88 wchar_t result[100];
89 if (result == NULL)
91 printf ("error: calloc (%d, %zu): %m", ret + 1, sizeof (wchar_t));
92 return 1;
95 ret = swprintf (result, 100, L"%133000.999999999x", 17);
96 if (ret >= 0)
98 printf ("error: swprintf: incorrect result %d\n", ret);
99 return 1;
103 return 0;
106 #define TEST_FUNCTION do_test ()
107 #include "../test-skeleton.c"