[Scummvm-git-logs] scummvm master -> 71317aa0fe07b8a21ea07a57ea4ce9f9a505ceed
bluegr
noreply at scummvm.org
Fri Dec 4 00:16:25 UTC 2026
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
71317aa0fe COMMON: Fix RBTree move constructor leaving the source owning its nodes
Commit: 71317aa0fe07b8a21ea07a57ea4ce9f9a505ceed
https://github.com/scummvm/scummvm/commit/71317aa0fe07b8a21ea07a57ea4ce9f9a505ceed
Author: Gianluca Boiano (morf3089 at gmail.com)
Date: 2026-12-04T02:16:20+02:00
Commit Message:
COMMON: Fix RBTree move constructor leaving the source owning its nodes
The move constructor took over the root, leftmost node and size of the
source tree without resetting them, so both trees owned the same nodes.
Destroying the moved-from tree freed them and left the new one dangling,
which happens whenever a Common::Array of StableMaps grows.
Changed paths:
A test/common/stablemap.h
common/rb_tree.h
diff --git a/common/rb_tree.h b/common/rb_tree.h
index a642ec5351c..e70f70249fe 100644
--- a/common/rb_tree.h
+++ b/common/rb_tree.h
@@ -133,6 +133,9 @@ public:
/** Construct an RBTree by moving the contents of the given tree (using the C++11 move semantics). */
RBTree(RBTree &&other) : _root(other._root), _leftmost(other._leftmost), _size(other._size), _comp(Common::move(other._comp)) {
+ other._root = nullptr;
+ other._leftmost = nullptr;
+ other._size = 0;
}
/** Assign the given tree to this tree. */
diff --git a/test/common/stablemap.h b/test/common/stablemap.h
new file mode 100644
index 00000000000..155aa6347f2
--- /dev/null
+++ b/test/common/stablemap.h
@@ -0,0 +1,38 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/array.h"
+#include "common/stablemap.h"
+#include "common/str.h"
+
+class StableMapTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_move_construct() {
+ Common::StableMap<Common::String, int> *source = new Common::StableMap<Common::String, int>();
+ (*source)["a"] = 1;
+ (*source)["b"] = 2;
+
+ Common::StableMap<Common::String, int> moved(Common::move(*source));
+ TS_ASSERT(source->empty());
+ delete source;
+
+ TS_ASSERT_EQUALS(moved.size(), 2u);
+ TS_ASSERT_EQUALS(moved["a"], 1);
+ TS_ASSERT_EQUALS(moved["b"], 2);
+ }
+
+ void test_array_growth() {
+ // Growing an array moves its elements to new storage and destroys the old ones.
+ Common::Array<Common::StableMap<int, int> > maps;
+ for (int i = 0; i < 64; ++i) {
+ Common::StableMap<int, int> map;
+ map[i] = i * 2;
+ maps.push_back(map);
+ }
+
+ for (int i = 0; i < 64; ++i) {
+ TS_ASSERT_EQUALS(maps[i].size(), 1u);
+ TS_ASSERT_EQUALS(maps[i][i], i * 2);
+ }
+ }
+};
More information about the Scummvm-git-logs
mailing list