diff --git a/ubb-la/gui.c b/ubb-la/gui.c index fb15c20..d66d92f 100644 --- a/ubb-la/gui.c +++ b/ubb-la/gui.c @@ -10,13 +10,10 @@ * (at your option) any later version. */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE /* for vasprintf */ -#endif - #include #include #include +#include #include "SDL.h" #include "SDL_gfxPrimitives.h" @@ -124,13 +121,14 @@ static void textf(int x, int y, uint32_t color, const char *fmt, ...) va_list ap; char *tmp, *s; uint8_t *p; - int ix, iy; + int n, ix, iy; va_start(ap, fmt); - if (vasprintf(&tmp, fmt, ap) < 0) { - perror("vasprintf"); - exit(1); - } + n = vsnprintf(NULL, 0, fmt, ap); + va_end(ap); + tmp = alloca(n+1); + va_start(ap, fmt); + vsnprintf(tmp, n+1, fmt, ap); va_end(ap); for (s = tmp; *s; s++) { @@ -143,7 +141,6 @@ static void textf(int x, int y, uint32_t color, const char *fmt, ...) } x += 8; } - free(tmp); }