Changeset - r25450:7e9533370994
[Not reviewed]
master
0 1 0
frosch - 3 years ago 2021-05-12 21:40:03
frosch@openttd.org
Fix #9256, 12e43c697d2: invalid read after free. (#9258)

This also changes ScriptEventVehicleAutoReplaced when replacing wagons:
The event is now only spawned, if the head engine changes, so only if the VehicleID of the consist changes.
Previously replacing wagons spawned an event with OldVehicleID==NewVehicleID.
1 file changed with 2 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -614,6 +614,7 @@ static CommandCost ReplaceChain(Vehicle 
 
				/* Success ! */
 
				if ((flags & DC_EXEC) != 0 && new_head != old_head) {
 
					*chain = new_head;
 
					AI::NewEvent(old_head->owner, new ScriptEventVehicleAutoReplaced(old_head->index, new_head->index));
 
				}
 

	
 
				/* Transfer cargo of old vehicles and sell them */
 
@@ -631,10 +632,7 @@ static CommandCost ReplaceChain(Vehicle 
 
					cost.AddCost(DoCommand(0, w->index, 0, flags | DC_AUTOREPLACE, GetCmdSellVeh(w)));
 
					if ((flags & DC_EXEC) != 0) {
 
						old_vehs[i] = nullptr;
 
						if (i == 0) {
 
							AI::NewEvent(old_head->owner, new ScriptEventVehicleAutoReplaced(old_head->index, new_head->index));
 
							old_head = nullptr;
 
						}
 
						if (i == 0) old_head = nullptr;
 
					}
 
				}
 

	
0 comments (0 inline, 0 general)