printf oob regression test
[libc-test] / src / regression / printf-1e9-oob.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "test.h"
4
5 static void t(const char *fmt, double d, const char *want)
6 {
7         char buf[256];
8         int n = strlen(want);
9         int r = snprintf(buf, sizeof buf, fmt, d);
10         if (r != n || memcmp(buf, want, n+1) != 0)
11                 t_error("snprintf(\"%s\",%f) want %s got %s\n", fmt, d, want, buf);
12 }
13
14 int main()
15 {
16         // fill stack with something
17         t("%.1f", 123123123123123.0, "123123123123123.0");
18         // test for out-of-bounds access
19         t("%g", 999999999.0, "1e+09");
20         t("%.3e", 999999999.75, "1.000e+09");
21         return t_status;
22 }