Changeset - r23103:dab285bdadbc
[Not reviewed]
master
0 1 0
Niels Martin Hansen - 5 years ago 2019-01-05 13:30:59
nielsm@indvikleren.dk
Fix 6a3d411: Silence truncation warning
1 file changed with 2 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -692,28 +692,29 @@ CommandCost CmdBuildTunnel(TileIndex sta
 

	
 
		/* CMD_TERRAFORM_LAND may append further items to _cleared_object_areas,
 
		 * however it will never erase or re-order existing items.
 
		 * _cleared_object_areas is a value-type SmallVector, therefore appending items
 
		 * may result in a backing-store re-allocation, which would invalidate the coa pointer.
 
		 * The index of the coa pointer into the _cleared_object_areas vector remains valid,
 
		 * and can be used safely after the CMD_TERRAFORM_LAND operation.
 
		 * Deliberately clear the coa pointer to avoid leaving dangling pointers which could
 
		 * inadvertently be dereferenced.
 
		 */
 
		assert(coa >= _cleared_object_areas.Begin() && coa < _cleared_object_areas.End());
 
		size_t coa_index = coa - _cleared_object_areas.Begin();
 
		assert(coa_index < UINT_MAX); // more than 2**32 cleared areas would be a bug in itself
 
		coa = NULL;
 

	
 
		ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
 
		_cleared_object_areas[coa_index].first_tile = old_first_tile;
 
		_cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
 
		if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
 
		cost.AddCost(ret);
 
	}
 
	cost.AddCost(_price[PR_BUILD_TUNNEL]);
 

	
 
	/* Pay for the rail/road in the tunnel including entrances */
 
	switch (transport_type) {
 
		case TRANSPORT_ROAD: cost.AddCost((tiles + 2) * _price[PR_BUILD_ROAD] * 2); break;
 
		case TRANSPORT_RAIL: cost.AddCost((tiles + 2) * RailBuildCost(railtype)); break;
 
		default: NOT_REACHED();
 
	}
 

	
0 comments (0 inline, 0 general)