From 39271cfe09f3e395cebb5b577f2fe687ec4d59d2 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Tue, 26 Sep 2006 12:29:23 +0000 Subject: Fixed Crawl's home-rolled snprintf for -pedantic. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup@140 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/libutil.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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); -- cgit v1.2.3-54-g00ecf