NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
patch for std_sprintf crash


Joined: 30 May 2005
Posts: 7
Reply with quote
If you try to print a string longer than std_sprintf's default 512 char buffer size, dbg-cli crashes. At least for me, on a x86_64 linux machine.

Here's a fix:
Code:

--- dbgbase/dbgbase_globals.cpp.orig     2006-02-03 10:22:02.000000000 -0800
+++ dbgbase/dbgbase_globals.cpp 2006-02-03 10:55:23.000000000 -0800
@@ -141,14 +141,16 @@
 }

 int __cdecl std_sprintf(std::string& buf, const char *format ...) {
- va_list args;
+    va_list args, args_copy;
  int sz, ret_val, i;
  char *cbuf = NULL;

  va_start(args, format);
  for (sz=512, i=0; i < 16; i++, sz=sz*2) {
+     va_copy(args_copy, args);
   cbuf = new char[sz];
-  ret_val = vsnprintf(cbuf, sz, format, args);
+  ret_val = vsnprintf(cbuf, sz, format, args_copy);
+  va_end(args_copy);
   if (ret_val >= 0 && ret_val < sz) break;
   delete cbuf;
   cbuf = NULL;


Note this patch is similar to viewtopic.php?t=5855&highlight=stdsprintf&sid=a9226387795e352f550e33a9bd711eae but that did not prevent my crash, while this one does. An important difference!
View user's profileFind all posts by dcohenSend private message
patch for std_sprintf crash
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic