From b89d984cca6c09e60c1941b746162903d81bb323 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 6 Apr 2014 01:37:24 +0200 Subject: [PATCH] printf oob regression test --- src/regression/printf-1e9-oob.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/regression/printf-1e9-oob.c diff --git a/src/regression/printf-1e9-oob.c b/src/regression/printf-1e9-oob.c new file mode 100644 index 0000000..3d7dccf --- /dev/null +++ b/src/regression/printf-1e9-oob.c @@ -0,0 +1,22 @@ +#include +#include +#include "test.h" + +static void t(const char *fmt, double d, const char *want) +{ + char buf[256]; + int n = strlen(want); + int r = snprintf(buf, sizeof buf, fmt, d); + if (r != n || memcmp(buf, want, n+1) != 0) + t_error("snprintf(\"%s\",%f) want %s got %s\n", fmt, d, want, buf); +} + +int main() +{ + // fill stack with something + t("%.1f", 123123123123123.0, "123123123123123.0"); + // test for out-of-bounds access + t("%g", 999999999.0, "1e+09"); + t("%.3e", 999999999.75, "1.000e+09"); + return t_status; +} -- 2.20.1