summaryrefslogtreecommitdiff
path: root/vehicle_gui.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2005-10-25 19:52:25 +0000
committerpeter1138 <peter1138@openttd.org>2005-10-25 19:52:25 +0000
commit6b0bbde53d72fc0e75c020acf9fcd435b231ac37 (patch)
treef492aec44aaa13c7dca77fc7169b529521519d08 /vehicle_gui.c
parent85002131fe9ddd539e20e96796908d657e0de472 (diff)
downloadopenttd-6b0bbde53d72fc0e75c020acf9fcd435b231ac37.tar.xz
(svn r3089) Fix possible issue with out-of-bounds array access in replace vehicle gui, and add brief commenting.
Diffstat (limited to 'vehicle_gui.c')
-rw-r--r--vehicle_gui.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/vehicle_gui.c b/vehicle_gui.c
index bff8ec1b1..7c8914758 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -821,13 +821,22 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
}
}
- if ( selected_id[0] == selected_id[1] || p->engine_replacement[selected_id[0]] == selected_id[1]
- || selected_id[0] == -1 || selected_id[1] == -1 )
+ // Disable the "Start Replacing" button if:
+ // Either list is empty
+ // or Both lists have the same vehicle selected
+ // or The right list (new replacement) has the existing replacement vehicle selected
+ if (selected_id[0] == -1 || selected_id[1] == -1 ||
+ selected_id[0] == selected_id[1] ||
+ p->engine_replacement[selected_id[0]] == selected_id[1])
SETBIT(w->disabled_state, 4);
else
CLRBIT(w->disabled_state, 4);
- if (p->engine_replacement[selected_id[0]] == INVALID_ENGINE || selected_id[0] == -1)
+ // Disable the "Stop Replacing" button if:
+ // The left list (existing vehicle) is empty
+ // or The selected vehicle has no replacement set up
+ if (selected_id[0] == -1 ||
+ p->engine_replacement[selected_id[0]] == INVALID_ENGINE)
SETBIT(w->disabled_state, 6);
else
CLRBIT(w->disabled_state, 6);