summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/libutil.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc
index 2e256b03cc..e03ddc1e78 100644
--- a/crawl-ref/source/libutil.cc
+++ b/crawl-ref/source/libutil.cc
@@ -400,7 +400,12 @@ int snprintf( char *str, size_t size, const char *format, ... )
va_list argp;
va_start( argp, format );
- char buff[ 10 * size ]; // hopefully enough
+ char *buff = new char [ 10 * size ]; // hopefully enough
+ if (!buff)
+ {
+ fprintf(stderr, "Out of memory\n");
+ exit(1);
+ }
vsprintf( buff, format, argp );
strncpy( str, buff, size );
@@ -410,6 +415,8 @@ int snprintf( char *str, size_t size, const char *format, ... )
if ((unsigned int) ret == size - 1 && strlen( buff ) >= size)
ret = -1;
+ delete [] buff;
+
va_end( argp );
return (ret);