]> git.ipfire.org Git - thirdparty/glibc.git/blob - stdio-common/bug22.c
vfprintf: Fix memory with large width and precision [BZ #19931]
[thirdparty/glibc.git] / stdio-common / bug22.c
1 /* BZ #5424 */
2 #include <stdio.h>
3 #include <errno.h>
4
5 /* INT_MAX + 1 */
6 #define N 2147483648
7
8 /* (INT_MAX / 2) + 2 */
9 #define N2 1073741825
10
11 /* INT_MAX - 3 */
12 #define N3 2147483644
13
14 #define STRINGIFY(S) #S
15 #define MAKE_STR(S) STRINGIFY(S)
16
17 #define SN MAKE_STR(N)
18 #define SN2 MAKE_STR(N2)
19 #define SN3 MAKE_STR(N3)
20
21 static int
22 do_test (void)
23 {
24 int ret;
25
26 FILE *fp = fopen ("/dev/null", "w");
27 if (fp == NULL)
28 {
29 puts ("cannot open /dev/null");
30 return 1;
31 }
32
33 ret = fprintf (fp, "%" SN "d", 1);
34 printf ("ret = %d\n", ret);
35 if (ret != -1 || errno != EOVERFLOW)
36 return 1;
37
38 ret = fprintf (fp, "%." SN "d", 1);
39 printf ("ret = %d\n", ret);
40 if (ret != -1 || errno != EOVERFLOW)
41 return 1;
42
43 ret = fprintf (fp, "%." SN3 "d", 1);
44 printf ("ret = %d\n", ret);
45 if (ret != -1 || errno != EOVERFLOW)
46 return 1;
47
48 ret = fprintf (fp, "%" SN2 "d%" SN2 "d", 1, 1);
49 printf ("ret = %d\n", ret);
50
51 return ret != -1 || errno != EOVERFLOW;
52 }
53
54 #define TIMEOUT 60
55 #define TEST_FUNCTION do_test ()
56 #include "../test-skeleton.c"