From 1c722d6c222d80e550d948a77f318083e69efdc4 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 24 Dec 2012 12:03:25 +0100 Subject: [PATCH] test: make fmt() not leak memory --- test/runner.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/runner.c b/test/runner.c index 5925ec75..01d6c773 100644 --- a/test/runner.c +++ b/test/runner.c @@ -39,10 +39,18 @@ static void log_progress(int total, int passed, int failed, const char* name) { const char* fmt(double d) { + static char buf[1024]; + static char* p; uint64_t v; - char* p; - p = (char *) calloc(1, 32) + 31; /* leaks memory */ + if (p == NULL) + p = buf; + + p += 31; + + if (p >= buf + sizeof(buf)) + return ""; + v = (uint64_t) d; #if 0 /* works but we don't care about fractional precision */