1570af302Sopenharmony_ci// commit 109048e031f39fbb370211fde44ababf6c04c8fb 2014-04-07 2570af302Sopenharmony_ci// float printf out-of-bounds access 3570af302Sopenharmony_ci#include <stdio.h> 4570af302Sopenharmony_ci#include <string.h> 5570af302Sopenharmony_ci#include "test.h" 6570af302Sopenharmony_ci 7570af302Sopenharmony_cistatic void t(const char *fmt, double d, const char *want) 8570af302Sopenharmony_ci{ 9570af302Sopenharmony_ci char buf[256]; 10570af302Sopenharmony_ci int n = strlen(want); 11570af302Sopenharmony_ci int r = snprintf(buf, sizeof buf, fmt, d); 12570af302Sopenharmony_ci if (r != n || memcmp(buf, want, n+1) != 0) 13570af302Sopenharmony_ci t_error("snprintf(\"%s\",%f) want %s got %s\n", fmt, d, want, buf); 14570af302Sopenharmony_ci} 15570af302Sopenharmony_ci 16570af302Sopenharmony_ciint main() 17570af302Sopenharmony_ci{ 18570af302Sopenharmony_ci // fill stack with something 19570af302Sopenharmony_ci t("%.1f", 123123123123123.0, "123123123123123.0"); 20570af302Sopenharmony_ci // test for out-of-bounds access 21570af302Sopenharmony_ci t("%g", 999999999.0, "1e+09"); 22570af302Sopenharmony_ci t("%.3e", 999999999.75, "1.000e+09"); 23570af302Sopenharmony_ci return t_status; 24570af302Sopenharmony_ci} 25