]>
git.ipfire.org Git - thirdparty/glibc.git/blob - stdio-common/tst-sprintf.c
13 if (sprintf (buf
, "%.0ls", L
"foo") != 0
16 puts ("sprintf (buf, \"%.0ls\", L\"foo\") produced some output");
20 #define SIZE (1024*70000)
23 char *dst
= malloc (SIZE
+ 1);
27 puts ("memory allocation failure");
32 sprintf (dst
, "%*s", SIZE
, "");
33 if (strnlen (dst
, SIZE
+ 1) != SIZE
)
35 puts ("sprintf (dst, \"%*s\", " STR(SIZE
) ", \"\") did not produce enough output");
41 if (sprintf (buf
, "%1$d%3$.*2$s%4$d", 7, 67108863, "x", 8) != 3
42 || strcmp (buf
, "7x8") != 0)
44 printf ("sprintf (buf, \"%%1$d%%3$.*2$s%%4$d\", 7, 67108863, \"x\", 8) produced `%s' output", buf
);
48 /* We are testing a corner case of the sprintf format string here. */
49 DIAG_PUSH_NEEDS_COMMENT
;
50 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
51 int n
= sprintf (buf
, "%67108863.16\"%d", 7);
52 DIAG_POP_NEEDS_COMMENT
;
54 if (n
!= 14 || strcmp (buf
, "%67108863.16\"7") != 0)
56 printf ("sprintf (buf, \"%%67108863.16\\\"%%d\", 7) produced `%s' output",
61 /* We are testing a corner case of the sprintf format string here. */
62 DIAG_PUSH_NEEDS_COMMENT
;
63 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
64 n
= sprintf (buf
, "%*\"%d", 0x3ffffff, 7);
65 DIAG_POP_NEEDS_COMMENT
;
67 if (n
!= 11 || strcmp (buf
, "%67108863\"7") != 0)
69 printf ("sprintf (buf, \"%%*\\\"%%d\", 0x3ffffff, 7) produced `%s' output", buf
);
73 if (setlocale (LC_ALL
, "de_DE.UTF-8") == NULL
)
75 puts ("cannot set locale");
78 else if (sprintf (buf
, "%.8s\n", "Foo: \277") != 7
79 || strcmp (buf
, "Foo: \277\n") != 0)
81 printf ("sprintf (buf, \"%%.8s\\n\", \"Foo: \\277\") produced '%s' output\n", buf
);
88 #define TEST_FUNCTION do_test ()
89 #include "../test-skeleton.c"