changeset 16038:cf5ef4e1aa91 draft

(svn r20731) -Fix (r20739): SmallVector did not have an assignment operator, causing invalid memory reads / double free
author yexo <yexo@openttd.org>
date Fri, 03 Sep 2010 23:04:02 +0000
parents fb390c835e3f
children 6f17901e8aec
files src/core/smallvec_type.hpp src/landscape.cpp
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -36,12 +36,20 @@
 public:
 	SmallVector() : data(NULL), items(0), capacity(0) { }
 
-	template<uint X>
+	template <uint X>
 	SmallVector(const SmallVector<T, X> &other) : data(NULL), items(0), capacity(0)
 	{
 		MemCpyT<T>(this->Append(other.Length()), other.Begin(), other.Length());
 	}
 
+	template <uint X>
+	SmallVector &operator=(const SmallVector<T, X> &other)
+	{
+		this->Reset();
+		MemCpyT<T>(this->Append(other.Length()), other.Begin(), other.Length());
+		return *this;
+	}
+
 	~SmallVector()
 	{
 		free(this->data);
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -638,7 +638,7 @@
 
 	for (int x = sx; x <= ex; ++x) {
 		for (int y = sy; y <= ey; ++y) {
-			SmallVector<TileArea, 1> object_areas = _cleared_object_areas;
+			SmallVector<TileArea, 1> object_areas(_cleared_object_areas);
 			CommandCost ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
 			_cleared_object_areas = object_areas;
 			if (ret.Failed()) {