Changeset - r16028:f7cfe78e8c66
[Not reviewed]
master
0 2 0
yexo - 14 years ago 2010-09-03 23:04:02
yexo@openttd.org
(svn r20731) -Fix (r20739): SmallVector did not have an assignment operator, causing invalid memory reads / double free
2 files changed with 10 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/core/smallvec_type.hpp
Show inline comments
 
@@ -33,18 +33,26 @@ protected:
 
	uint items;    ///< The number of items stored
 
	uint capacity; ///< The available space for storing items
 

	
 
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);
 
	}
 

	
 
	/**
src/landscape.cpp
Show inline comments
 
@@ -635,13 +635,13 @@ CommandCost CmdClearArea(TileIndex tile,
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost last_error = CMD_ERROR;
 
	bool had_success = false;
 

	
 
	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()) {
 
				last_error = ret;
 
				continue;
 
			}
0 comments (0 inline, 0 general)