From a55397c5f6dbac3ded5f5d044e1c2f2603ebb2f5 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 17 Jul 2012 23:36:00 +0000 Subject: [PATCH] - more safe way to accumulate stack trace and not run out of buffer space. --- .../sources/platform/sdl/platform_util.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/shared_lib/sources/platform/sdl/platform_util.cpp b/source/shared_lib/sources/platform/sdl/platform_util.cpp index d8d7ca42a..31b46e644 100644 --- a/source/shared_lib/sources/platform/sdl/platform_util.cpp +++ b/source/shared_lib/sources/platform/sdl/platform_util.cpp @@ -186,6 +186,7 @@ string PlatformExceptionHandler::getStackTrace() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); char szBuf[8096]=""; + string strBuf = ""; for(size_t i = 1; i < stack_depth; i++) { void *lineAddress = stack_addrs[i]; //getStackAddress(stackIndex); @@ -223,15 +224,22 @@ string PlatformExceptionHandler::getStackTrace() { } //fprintf(out, " %s:%s\n", stack.strings[i], function); - sprintf(szBuf,"%s:%s address [%p]",stack_strings[i],function,lineAddress); + //sprintf(szBuf,"%s:%s address [%p]",stack_strings[i],function,lineAddress); + strBuf = string(stack_strings[i]) + ":" + string(function); + sprintf(szBuf,"address [%p]",lineAddress); + strBuf += szBuf; } else { // didn't find the mangled name, just print the whole line //fprintf(out, " %s\n", stack.strings[i]); - sprintf(szBuf,"%s address [%p]",stack_strings[i],lineAddress); + //sprintf(szBuf,"%s address [%p]",stack_strings[i],lineAddress); + strBuf = stack_strings[i]; + sprintf(szBuf,"address [%p]",lineAddress); + strBuf += szBuf; } - errMsg += string(szBuf); + //errMsg += string(szBuf); + errMsg += strBuf; char file[8096]=""; int line = getFileAndLine(function, lineAddress, file, 8096); if(line >= 0) {