From f06f586d186ef674c92b6e5dd2c841a9afb17c66 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 5 Feb 2020 03:10:07 -0800 Subject: [PATCH] sprintf warnings --- stb_sprintf.h | 2 +- tests/test_sprintf.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stb_sprintf.h b/stb_sprintf.h index 630d851..b899e63 100644 --- a/stb_sprintf.h +++ b/stb_sprintf.h @@ -182,7 +182,7 @@ PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC): #ifndef STB_SPRINTF_MIN #define STB_SPRINTF_MIN 512 // how many characters per callback #endif -typedef char *STBSP_SPRINTFCB(char *buf, void *user, int len); +typedef char *STBSP_SPRINTFCB(const char *buf, void *user, int len); #ifndef STB_SPRINTF_DECORATE #define STB_SPRINTF_DECORATE(name) stbsp_##name // define this before including if you want to change the names diff --git a/tests/test_sprintf.c b/tests/test_sprintf.c index 674e2c7..ce18874 100644 --- a/tests/test_sprintf.c +++ b/tests/test_sprintf.c @@ -111,10 +111,10 @@ int main() #if __STDC_VERSION__ >= 199901L #if USE_STB CHECK4("Inf Inf NaN", "%g %G %f", INFINITY, INFINITY, NAN); - CHECK1("N", "%.1g", NAN); + CHECK2("N", "%.1g", NAN); #else CHECK4("inf INF nan", "%g %G %f", INFINITY, INFINITY, NAN); - CHECK1("nan", "%.1g", NAN); + CHECK2("nan", "%.1g", NAN); #endif #endif @@ -150,9 +150,9 @@ int main() assert(strncmp(buf, "37778931862957161709568.000000", 17) == 0); n = SNPRINTF(buf, 10, "number %f", 123.456789); assert(strcmp(buf, "number 12") == 0); - assert(n == (USE_STB ? 9 : 17)); // written vs would-be written bytes + assert(n == 17); // written vs would-be written bytes n = SNPRINTF(buf, 0, "7 chars"); - assert(n == (USE_STB ? 0 : 7)); + assert(n == 7); // stb_sprintf uses internal buffer of 512 chars - test longer string assert(SPRINTF(buf, "%d %600s", 3, "abc") == 603); assert(strlen(buf) == 603);