]>
git.saurik.com Git - apple/libc.git/blob - tests/printf.c
2 #include <sys/resource.h>
9 #include <os/assumes.h>
11 #include "darwintest.h"
12 #include "darwintest_utils.h"
14 static void crash_callback(const char *str
) {
15 T_PASS("Crashed with \"%s\"", str
);
19 T_DECL(sprintf_percent_n
, "Test of %n")
24 char *fmt
= "%010d%n";
26 T_EXPECT_POSIX_SUCCESS((ret
= snprintf(str
, sizeof(str
), fmt
, 0, &len
)), NULL
);
27 T_EXPECT_EQ(len
, ret
, NULL
);
30 strlcpy(fmt_buf
, fmt
, sizeof(fmt_buf
));
32 os_set_crash_callback(crash_callback
);
33 snprintf(str
, sizeof(str
), fmt_buf
, 0, &len
);
34 T_ASSERT_FAIL("Should have crashed on dynamic %%n");
38 #define STRSIZE (1024 * 1024 * 256)
40 T_DECL(printf_PR_30663523
, "Test for PR-30663523",
41 T_META_CHECK_LEAKS(NO
))
44 asprintf(&temp_path
, "%s/%s", dt_tmpdir(), "big_file");
47 char *x
= calloc(1, 0x80000001);
48 memset(x
, 0x41, 0x80000001);
50 FILE *f
= fopen(temp_path
, "w");
51 int len
= fprintf(f
, "%s", x
);
52 T_EXPECT_EQ(len
, EOF
, "fprintf should return EOF when string is longer than INT_MAX");
57 char *x
= calloc(1, STRSIZE
);
58 memset(x
, 0x41, STRSIZE
- 1);
60 FILE *f
= fopen(temp_path
, "w");
61 int len
= fprintf(f
, "%s%s%s%s%s%s%s%s%s%s", x
,x
,x
,x
,x
,x
,x
,x
,x
,x
);
62 T_EXPECT_EQ(len
, EOF
, "fprintf should return EOF when output string is longer than INT_MAX");
66 #endif // !TARGET_OS_IPHONE