[Scummvm-cvs-logs] SF.net SVN: scummvm:[50050] scummvm/trunk/common/str.cpp

criezy at users.sourceforge.net criezy at users.sourceforge.net
Sat Jun 19 17:35:21 CEST 2010


Revision: 50050
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50050&view=rev
Author:   criezy
Date:     2010-06-19 15:35:21 +0000 (Sat, 19 Jun 2010)

Log Message:
-----------
Fix an issue in String::ensureCapacity() when the string is shared. It could allocate two much memory as it was at least doubling the current capacity even when this one was sufficient.
It fixes a crash in GUI::Widget::cleanupHotkey() as the capacity of the string was doubled at each iteration once it was too long for the internal storage (only to add one character to the string). This ended up in a bad_alloc exception after a few iterations.

Modified Paths:
--------------
    scummvm/trunk/common/str.cpp

Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp	2010-06-19 11:08:41 UTC (rev 50049)
+++ scummvm/trunk/common/str.cpp	2010-06-19 15:35:21 UTC (rev 50050)
@@ -151,7 +151,11 @@
 		// We need to allocate storage on the heap!
 
 		// Compute a suitable new capacity limit
-		newCapacity = MAX(curCapacity * 2, computeCapacity(new_size+1));
+		// If the current capacity is sufficient we use the same capacity
+		if (new_size < curCapacity)
+			newCapacity = curCapacity;
+		else
+			newCapacity = MAX(curCapacity * 2, computeCapacity(new_size+1));
 
 		// Allocate new storage
 		newStorage = new char[newCapacity];


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list