[Scummvm-cvs-logs] SF.net SVN: scummvm:[34317] scummvm/trunk/common/str.cpp
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed Sep 3 20:38:04 CEST 2008
Revision: 34317
http://scummvm.svn.sourceforge.net/scummvm/?rev=34317&view=rev
Author: fingolfin
Date: 2008-09-03 18:38:01 +0000 (Wed, 03 Sep 2008)
Log Message:
-----------
Fix nasty off-by-one errors
Modified Paths:
--------------
scummvm/trunk/common/str.cpp
Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp 2008-09-03 18:07:31 UTC (rev 34316)
+++ scummvm/trunk/common/str.cpp 2008-09-03 18:38:01 UTC (rev 34317)
@@ -35,10 +35,7 @@
#endif
static uint32 computeCapacity(uint32 len) {
- // By default, for the capacity we use the nearest multiple of 32
- // that leaves at least 16 chars of extra space (in case the string
- // grows a bit).
- len += 16;
+ // By default, for the capacity we use the next multiple of 32
return ((len + 32 - 1) & ~0x1F);
}
@@ -70,7 +67,7 @@
if (len >= _builtinCapacity) {
// Not enough internal storage, so allocate more
- _extern._capacity = computeCapacity(len);
+ _extern._capacity = computeCapacity(len+1);
_extern._refCount = 0;
_str = (char *)malloc(_extern._capacity);
assert(_str != 0);
@@ -136,7 +133,7 @@
// Special case: If there is enough space, and we do not share
// the storage, then there is nothing to do.
- if (!isShared && new_size <= curCapacity)
+ if (!isShared && new_size < curCapacity)
return;
if (isShared && new_size < _builtinCapacity) {
@@ -147,7 +144,7 @@
// We need to allocate storage on the heap!
// Compute a suitable new capacity limit
- newCapacity = MAX(curCapacity * 2, computeCapacity(new_size));
+ newCapacity = MAX(curCapacity * 2, computeCapacity(new_size+1));
// Allocate new storage
newStorage = (char *)malloc(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