Add guards for nullptr and (-1) pointer accesses

This commit is contained in:
Tomas Dittmann authored and Michael Steenbeek committed 2017-08-22 10:20:59 +02:00
1 parent d94c8ffa5e
commit 7d8695394c
9 files changed
+49 -6

No files matched your search

+6
View File
@@ -64,6 +64,12 @@ void scenery_paint(uint8 direction, sint32 height, rct_map_element* mapElement)
uint32 dword_F64EB0 = baseImageid;
rct_scenery_entry *entry = get_small_scenery_entry(mapElement->properties.scenery.type);
if (entry == (rct_scenery_entry*)-1)
{
return;
}
baseImageid = entry->image + direction;
boxlength.x = 2;
boxlength.y = 2;
+1 -1
View File
@@ -6158,7 +6158,7 @@ static sint32 peep_update_patrolling_find_watering(rct_peep* peep){
rct_scenery_entry* sceneryEntry = get_small_scenery_entry(map_element->properties.scenery.type);
if (!(sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_CAN_BE_WATERED)){
if (sceneryEntry == (rct_scenery_entry*)-1 || !(sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_CAN_BE_WATERED)){
continue;
}
+5 -1
View File
@@ -449,7 +449,7 @@ static money32 ride_calculate_income_per_hour(rct_ride *ride)
{
// Get entry by ride to provide better reporting
rct_ride_entry *entry = get_ride_entry_by_ride(ride);
if (entry == NULL) {
if (entry == NULL || entry == (rct_ride_entry*)-1) {
return 0;
}
money32 customersPerHour = ride_customers_per_hour(ride);
@@ -7687,6 +7687,10 @@ void ride_update_max_vehicles(sint32 rideIndex)
return;
rct_ride_entry *rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == (rct_ride_entry*)-1)
{
return;
}
rct_ride_entry_vehicle *vehicleEntry;
uint8 numCarsPerTrain, numVehicles;
sint32 maxNumTrains;
+3
View File
@@ -1563,6 +1563,9 @@ static money32 track_remove(uint8 type, uint8 sequence, sint16 originX, sint16 o
found = 0;
mapElement = map_get_first_element_at(x / 32, y / 32);
do{
if (mapElement == NULL)
break;
if (mapElement->base_height != z / 8)
continue;
+20 -3
View File
@@ -732,10 +732,13 @@ static void vehicle_update_sound_params(rct_vehicle* vehicle)
sint32 v = vehicle->velocity;
rct_ride_entry* ride_type = get_ride_entry(vehicle->ride_subtype);
uint8 test = ride_type->vehicles[vehicle->vehicle_type].var_5A;
if (ride_type != (rct_ride_entry*)-1)
{
uint8 test = ride_type->vehicles[vehicle->vehicle_type].var_5A;
if (test & 1) {
v *= 2;
if (test & 1) {
v *= 2;
}
}
if (v < 0) {
v = -v;
@@ -4838,6 +4841,11 @@ static void vehicle_update_sound(rct_vehicle *vehicle)
ride = get_ride(vehicle->ride);
rideEntry = get_ride_entry(vehicle->ride_subtype);
if (rideEntry == (rct_ride_entry*)-1)
{
return;
}
rct_ride_entry_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type];
sint32 ecx = abs(vehicle->velocity) - 0x10000;
@@ -8637,6 +8645,11 @@ sint32 vehicle_update_track_motion(rct_vehicle *vehicle, sint32 *outStation)
rct_ride_entry *rideEntry = get_ride_entry(vehicle->ride_subtype);
rct_ride_entry_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle);
if (vehicleEntry == NULL)
{
return 0;
}
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_MINI_GOLF) {
return vehicle_update_track_motion_mini_golf(vehicle, outStation);
}
@@ -8943,6 +8956,10 @@ loc_6DC316:
rct_ride_entry_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle)
{
rct_ride_entry *rideEntry = get_ride_entry(vehicle->ride_subtype);
if (rideEntry == (rct_ride_entry*)-1)
{
return NULL;
}
return &rideEntry->vehicles[vehicle->vehicle_type];
}
+4
View File
@@ -2352,6 +2352,10 @@ void vehicle_paint(rct_vehicle *vehicle, sint32 imageDirection)
vehicleEntry = &CableLiftVehicle;
} else {
rideEntry = get_ride_entry(vehicle->ride_subtype);
if (rideEntry == (rct_ride_entry*)-1)
{
return;
}
vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type];
if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES) {
+1 -1
View File
@@ -1427,7 +1427,7 @@ static void window_ride_disable_tabs(rct_window *w)
rct_ride_entry *type = get_ride_entry(ride->subtype);
if (type == nullptr) {
if (type == nullptr || type == reinterpret_cast<rct_ride_entry*>(-1)) {
disabled_tabs |= 1 << WIDX_TAB_2 | 1 << WIDX_TAB_3 | 1 << WIDX_TAB_4 | 1 << WIDX_TAB_5 | 1 << WIDX_TAB_6
| 1 << WIDX_TAB_7 | 1 << WIDX_TAB_8 | 1 << WIDX_TAB_9 | 1 << WIDX_TAB_10;
} else if ((type->flags & RIDE_ENTRY_FLAG_DISABLE_COLOUR_TAB) != 0)
+4
View File
@@ -4093,6 +4093,10 @@ bool map_surface_is_blocked(sint16 x, sint16 y){
return true;
rct_scenery_entry* scenery = get_small_scenery_entry(mapElement->properties.scenery.type);
if (scenery == (rct_scenery_entry*)-1)
{
return false;
}
if (scenery->small_scenery.flags & SMALL_SCENERY_FLAG_FULL_TILE)
return true;
}
+5
View File
@@ -117,6 +117,11 @@ void scenery_update_age(sint32 x, sint32 y, rct_map_element *mapElement)
rct_scenery_entry *sceneryEntry;
sceneryEntry = get_small_scenery_entry(mapElement->properties.scenery.type);
if (sceneryEntry == (rct_scenery_entry*)-1)
{
return;
}
if (gCheatsDisablePlantAging &&
(sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_CAN_BE_WATERED)) {
return;