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