14 if (sprintf (buf
, "%.0ls", L
"foo") != 0
17 puts ("sprintf (buf, \"%.0ls\", L\"foo\") produced some output");
21 #define SIZE (1024*70000)
24 char *dst
= malloc (SIZE
+ 1);
28 puts ("memory allocation failure");
33 sprintf (dst
, "%*s", SIZE
, "");
34 if (strnlen (dst
, SIZE
+ 1) != SIZE
)
36 puts ("sprintf (dst, \"%*s\", " STR(SIZE
) ", \"\") did not produce enough output");
42 if (sprintf (buf
, "%1$d%3$.*2$s%4$d", 7, 67108863, "x", 8) != 3
43 || strcmp (buf
, "7x8") != 0)
45 printf ("sprintf (buf, \"%%1$d%%3$.*2$s%%4$d\", 7, 67108863, \"x\", 8) produced `%s' output", buf
);
49 /* We are testing a corner case of the sprintf format string here. */
50 DIAG_PUSH_NEEDS_COMMENT
;
51 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
52 int n
= sprintf (buf
, "%67108863.16\"%d", 7);
53 DIAG_POP_NEEDS_COMMENT
;
55 if (n
!= 14 || strcmp (buf
, "%67108863.16\"7") != 0)
57 printf ("sprintf (buf, \"%%67108863.16\\\"%%d\", 7) produced `%s' output",
62 /* We are testing a corner case of the sprintf format string here. */
63 DIAG_PUSH_NEEDS_COMMENT
;
64 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
65 n
= sprintf (buf
, "%*\"%d", 0x3ffffff, 7);
66 DIAG_POP_NEEDS_COMMENT
;
68 if (n
!= 11 || strcmp (buf
, "%67108863\"7") != 0)
70 printf ("sprintf (buf, \"%%*\\\"%%d\", 0x3ffffff, 7) produced `%s' output", buf
);
74 if (setlocale (LC_ALL
, "de_DE.UTF-8") == NULL
)
76 puts ("cannot set locale");
79 else if (sprintf (buf
, "%.8s\n", "Foo: \277") != 7
80 || strcmp (buf
, "Foo: \277\n") != 0)
82 printf ("sprintf (buf, \"%%.8s\\n\", \"Foo: \\277\") produced '%s' output\n", buf
);
89 #define TEST_FUNCTION do_test ()
90 #include "../test-skeleton.c"