Blame src/regression/printf-1e9-oob.c
|
Szabolcs Nagy |
79bf86 |
// commit 109048e031f39fbb370211fde44ababf6c04c8fb 2014-04-07
|
|
Szabolcs Nagy |
79bf86 |
// float printf out-of-bounds access
|
|
Szabolcs Nagy |
b89d98 |
#include <stdio.h>
|
|
Szabolcs Nagy |
b89d98 |
#include <string.h>
|
|
Szabolcs Nagy |
b89d98 |
#include "test.h"
|
|
Szabolcs Nagy |
b89d98 |
|
|
Szabolcs Nagy |
b89d98 |
static void t(const char *fmt, double d, const char *want)
|
|
Szabolcs Nagy |
b89d98 |
{
|
|
Szabolcs Nagy |
b89d98 |
char buf[256];
|
|
Szabolcs Nagy |
b89d98 |
int n = strlen(want);
|
|
Szabolcs Nagy |
b89d98 |
int r = snprintf(buf, sizeof buf, fmt, d);
|
|
Szabolcs Nagy |
b89d98 |
if (r != n || memcmp(buf, want, n+1) != 0)
|
|
Szabolcs Nagy |
b89d98 |
t_error("snprintf(\"%s\",%f) want %s got %s\n", fmt, d, want, buf);
|
|
Szabolcs Nagy |
b89d98 |
}
|
|
Szabolcs Nagy |
b89d98 |
|
|
Szabolcs Nagy |
b89d98 |
int main()
|
|
Szabolcs Nagy |
b89d98 |
{
|
|
Szabolcs Nagy |
b89d98 |
// fill stack with something
|
|
Szabolcs Nagy |
b89d98 |
t("%.1f", 123123123123123.0, "123123123123123.0");
|
|
Szabolcs Nagy |
b89d98 |
// test for out-of-bounds access
|
|
Szabolcs Nagy |
b89d98 |
t("%g", 999999999.0, "1e+09");
|
|
Szabolcs Nagy |
b89d98 |
t("%.3e", 999999999.75, "1.000e+09");
|
|
Szabolcs Nagy |
b89d98 |
return t_status;
|
|
Szabolcs Nagy |
b89d98 |
}
|