# HG changeset patch # User yexo # Date 1283555042 0 # Node ID cf5ef4e1aa918d0be7d1d7309bbd32b5eeca3bb7 # Parent fb390c835e3f301854d7085cb89899c5bc2597e0 (svn r20731) -Fix (r20739): SmallVector did not have an assignment operator, causing invalid memory reads / double free diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp --- 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 + template SmallVector(const SmallVector &other) : data(NULL), items(0), capacity(0) { MemCpyT(this->Append(other.Length()), other.Begin(), other.Length()); } + template + SmallVector &operator=(const SmallVector &other) + { + this->Reset(); + MemCpyT(this->Append(other.Length()), other.Begin(), other.Length()); + return *this; + } + ~SmallVector() { free(this->data); diff --git a/src/landscape.cpp b/src/landscape.cpp --- 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 object_areas = _cleared_object_areas; + SmallVector 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()) {