[Scummvm-cvs-logs] scummvm master -> 88319a727a5adc4888ec17e5ee091e14ce176afd

fingolfin max at quendi.de
Mon May 16 15:27:42 CEST 2011


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a564a10e7f TEST: Explicitly disable exceptions and std lib usage
88319a727a COMMON: Fix inserting an array into itself under certain conditions


Commit: a564a10e7f0afd99d7f0936c5b3e1acce31875b7
    https://github.com/scummvm/scummvm/commit/a564a10e7f0afd99d7f0936c5b3e1acce31875b7
Author: Max Horn (max at quendi.de)
Date: 2011-05-16T06:23:17-07:00

Commit Message:
TEST: Explicitly disable exceptions and std lib usage

Changed paths:
    test/module.mk



diff --git a/test/module.mk b/test/module.mk
index 3542ae2..4e5cbf6 100644
--- a/test/module.mk
+++ b/test/module.mk
@@ -9,7 +9,7 @@ TESTS        := $(srcdir)/test/common/*.h $(srcdir)/test/audio/*.h
 TEST_LIBS    := audio/libaudio.a common/libcommon.a
 
 #
-TEST_FLAGS   := --runner=StdioPrinter
+TEST_FLAGS   := --runner=StdioPrinter --no-std --no-eh
 TEST_CFLAGS  := -I$(srcdir)/test/cxxtest
 TEST_LDFLAGS := $(LIBS)
 TEST_CXXFLAGS := $(filter-out -Wglobal-constructors,$(CXXFLAGS))


Commit: 88319a727a5adc4888ec17e5ee091e14ce176afd
    https://github.com/scummvm/scummvm/commit/88319a727a5adc4888ec17e5ee091e14ce176afd
Author: Max Horn (max at quendi.de)
Date: 2011-05-16T06:23:17-07:00

Commit Message:
COMMON: Fix inserting an array into itself under certain conditions

Changed paths:
    common/array.h
    test/common/array.h



diff --git a/common/array.h b/common/array.h
index 87325d6..7ab4a1b 100644
--- a/common/array.h
+++ b/common/array.h
@@ -293,9 +293,12 @@ protected:
 		if (n) {
 			const uint idx = pos - _storage;
 			T *oldStorage = _storage;
-			if (_size + n > _capacity) {
+			if (_size + n > _capacity || (_storage <= first && first <= _storage + _size) ) {
 				// If there is not enough space, allocate more and
 				// copy old elements over.
+				// Likewise, if this is a self-insert, we allocate new
+				// storage to avoid conflicts. This is not the most efficient
+				// way to ensure that, but probably the simplest on.
 				allocCapacity(roundUpCapacity(_size + n));
 				copy(oldStorage, oldStorage + idx, _storage);
 				pos = _storage + idx;
diff --git a/test/common/array.h b/test/common/array.h
index f17edd3..c102704 100644
--- a/test/common/array.h
+++ b/test/common/array.h
@@ -107,6 +107,34 @@ class ArrayTestSuite : public CxxTest::TestSuite
 
 	}
 
+	void test_self_insert() {
+		Common::Array<int> array;
+		int i;
+
+		// Insert some data -- and make sure we have enough space for
+		// *twice* as much data. This way, there is no need to allocate
+		// new storage, so if the insert() operation is "clever", it
+		// will try to reuse the existing storage.
+		// This in turn may uncover bugs if the insertion code does not
+		// expect self-insertions.
+		array.reserve(128);
+		for (i = 0; i < 64; ++i)
+			array.push_back(i);
+
+		// Now insert the array into the middle of itself
+		array.insert_at(12, array);
+
+		// Verify integrity
+		TS_ASSERT_EQUALS(array.size(), 128UL);
+
+		for (i = 0; i < 12; ++i)
+			TS_ASSERT_EQUALS(array[i], i);
+		for (i = 0; i < 64; ++i)
+			TS_ASSERT_EQUALS(array[i+12], i);
+		for (i = 12; i < 64; ++i)
+			TS_ASSERT_EQUALS(array[i+64], i);
+	}
+
 
 	void test_remove_at() {
 		Common::Array<int> array;






More information about the Scummvm-git-logs mailing list