]>
Commit | Line | Data |
---|---|---|
13c5a442 | 1 | #include <stdio.h> |
fa4a36fd | 2 | #include <stdlib.h> |
13c5a442 UD |
3 | #include <string.h> |
4 | ||
5 | ||
6 | int | |
7 | main (void) | |
8 | { | |
9 | char buf[100]; | |
10 | int result = 0; | |
11 | ||
12 | if (sprintf (buf, "%.0ls", L"foo") != 0 | |
13 | || strlen (buf) != 0) | |
14 | { | |
40a54e4d | 15 | puts ("sprintf (buf, \"%.0ls\", L\"foo\") produced some output"); |
13c5a442 UD |
16 | result = 1; |
17 | } | |
18 | ||
40a54e4d UD |
19 | #define SIZE (1024*70000) |
20 | #define STR(x) #x | |
21 | ||
22 | char *dst = malloc (SIZE + 1); | |
23 | ||
24 | if (dst == NULL) | |
25 | { | |
26 | puts ("memory allocation failure"); | |
27 | result = 1; | |
28 | } | |
29 | else | |
30 | { | |
31 | sprintf (dst, "%*s", SIZE, ""); | |
32 | if (strnlen (dst, SIZE + 1) != SIZE) | |
33 | { | |
34 | puts ("sprintf (dst, \"%*s\", " STR(SIZE) ", \"\") did not produce enough output"); | |
35 | result = 1; | |
36 | } | |
37 | free (dst); | |
38 | } | |
39 | ||
0ecb606c JJ |
40 | if (sprintf (buf, "%1$d%3$.*2$s%4$d", 7, 67108863, "x", 8) != 3 |
41 | || strcmp (buf, "7x8") != 0) | |
42 | { | |
43 | printf ("sprintf (buf, \"%%1$d%%3$.*2$s%%4$d\", 7, 67108863, \"x\", 8) produced `%s' output", buf); | |
44 | result = 1; | |
45 | } | |
46 | ||
47 | if (sprintf (buf, "%67108863.16\"%d", 7) != 14 | |
48 | || strcmp (buf, "%67108863.16\"7") != 0) | |
49 | { | |
50 | printf ("sprintf (buf, \"%%67108863.16\\\"%%d\", 7) produced `%s' output", buf); | |
51 | result = 1; | |
52 | } | |
53 | ||
54 | if (sprintf (buf, "%*\"%d", 0x3ffffff, 7) != 11 | |
55 | || strcmp (buf, "%67108863\"7") != 0) | |
56 | { | |
57 | printf ("sprintf (buf, \"%%*\\\"%%d\", 0x3ffffff, 7) produced `%s' output", buf); | |
58 | result = 1; | |
59 | } | |
60 | ||
13c5a442 UD |
61 | return result; |
62 | } |