mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: add non-nullptr asserts in cases where it should never be nullptr
Though where similar calls are checked for nullptr as in those instances of the use of that function it can actually return nullptr. In other words, write down the assumption that the function never returns nullptr in an assert.
This commit is contained in:
parent
bcfe0fb076
commit
90f1768006
|
@ -866,6 +866,7 @@ static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
|
|||
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, nullptr);
|
||||
if (callback == CALLBACK_FAILED || callback == 0x400) return y;
|
||||
const GRFFile *grffile = Engine::Get(engine)->GetGRF();
|
||||
assert(grffile != nullptr);
|
||||
if (callback > 0x400) {
|
||||
ErrorUnknownCallbackResult(grffile->grfid, CBID_VEHICLE_ADDITIONAL_TEXT, callback);
|
||||
return y;
|
||||
|
|
|
@ -925,6 +925,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
|
|||
return false;
|
||||
}
|
||||
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
|
||||
assert(ci != nullptr);
|
||||
if (ci->client_playas == index) {
|
||||
IConsolePrint(CC_ERROR, "Cannot remove company: the server is connected to that company.");
|
||||
return true;
|
||||
|
|
|
@ -225,6 +225,7 @@ public:
|
|||
GameStrings *LoadTranslations()
|
||||
{
|
||||
const GameInfo *info = Game::GetInfo();
|
||||
assert(info != nullptr);
|
||||
std::string basename(info->GetMainScript());
|
||||
auto e = basename.rfind(PATHSEPCHAR);
|
||||
if (e == std::string::npos) return nullptr;
|
||||
|
|
|
@ -1532,6 +1532,7 @@ static void NetworkAutoCleanCompanies()
|
|||
|
||||
if (!_network_dedicated) {
|
||||
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
|
||||
assert(ci != nullptr);
|
||||
if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
|
||||
}
|
||||
|
||||
|
@ -1918,6 +1919,7 @@ void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
|
|||
if (client_id == CLIENT_ID_SERVER && _network_dedicated) return;
|
||||
|
||||
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
|
||||
assert(ci != nullptr);
|
||||
|
||||
/* No need to waste network resources if the client is in the company already! */
|
||||
if (ci->client_playas == company_id) return;
|
||||
|
|
|
@ -518,6 +518,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
|||
|
||||
{
|
||||
const Vehicle *w = v->Next();
|
||||
assert(w != nullptr);
|
||||
uint16 altitude = ClampToU16(v->z_pos - w->z_pos); // Aircraft height - shadow height
|
||||
byte airporttype = ATP_TTDP_LARGE;
|
||||
|
||||
|
|
|
@ -1464,6 +1464,9 @@ private:
|
|||
this->avails.push_back(c);
|
||||
} else {
|
||||
const GRFConfig *best = FindGRFConfig(c->ident.grfid, HasBit(c->flags, GCF_INVALID) ? FGCM_NEWEST : FGCM_NEWEST_VALID);
|
||||
/* Never triggers; FindGRFConfig returns either c, or a newer version of c. */
|
||||
assert(best != nullptr);
|
||||
|
||||
/*
|
||||
* If the best version is 0, then all NewGRF with this GRF ID
|
||||
* have version 0, so for backward compatibility reasons we
|
||||
|
|
|
@ -1251,6 +1251,7 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
|||
if (sel_ord >= v->GetNumOrders()) return CMD_ERROR;
|
||||
|
||||
Order *order = v->GetOrder(sel_ord);
|
||||
assert(order != nullptr);
|
||||
switch (order->GetType()) {
|
||||
case OT_GOTO_STATION:
|
||||
if (mof != MOF_NON_STOP && mof != MOF_STOP_LOCATION && mof != MOF_UNLOAD && mof != MOF_LOAD) return CMD_ERROR;
|
||||
|
|
|
@ -1223,6 +1223,7 @@ public:
|
|||
this->OrderClick_Nonstop(-1);
|
||||
} else {
|
||||
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
|
||||
assert(o != nullptr);
|
||||
ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
|
||||
o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
|
||||
}
|
||||
|
@ -1299,12 +1300,14 @@ public:
|
|||
|
||||
case WID_O_COND_COMPARATOR: {
|
||||
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
|
||||
assert(o != nullptr);
|
||||
ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_O_COND_VALUE: {
|
||||
const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
|
||||
assert(order != nullptr);
|
||||
uint value = order->GetConditionValue();
|
||||
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
|
||||
SetDParam(0, value);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
if (!IsValid(setting)) return -1;
|
||||
|
||||
const SettingDesc *sd = GetSettingFromName(setting);
|
||||
assert(sd != nullptr);
|
||||
return sd->AsIntSetting()->Read(&_settings_game);
|
||||
}
|
||||
|
||||
|
@ -35,6 +36,7 @@
|
|||
if (!IsValid(setting)) return false;
|
||||
|
||||
const SettingDesc *sd = GetSettingFromName(setting);
|
||||
assert(sd != nullptr);
|
||||
|
||||
if ((sd->flags & SF_NO_NETWORK_SYNC) != 0) return false;
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, ScriptOrder::OrderPositio
|
|||
if (order_position == ScriptOrder::ORDER_INVALID) return nullptr;
|
||||
}
|
||||
const Order *order = v->GetFirstOrder();
|
||||
assert(order != nullptr);
|
||||
while (order->GetType() == OT_IMPLICIT) order = order->next;
|
||||
while (order_position > 0) {
|
||||
order_position = (ScriptOrder::OrderPosition)(order_position - 1);
|
||||
|
@ -92,6 +93,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
|||
|
||||
int res = (int)order_position;
|
||||
const Order *order = v->orders->GetFirstOrder();
|
||||
assert(order != nullptr);
|
||||
for (; order->GetType() == OT_IMPLICIT; order = order->next) res++;
|
||||
while (order_position > 0) {
|
||||
order_position = (ScriptOrder::OrderPosition)(order_position - 1);
|
||||
|
@ -132,6 +134,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
|||
if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
|
||||
|
||||
const Order *order = ::Vehicle::Get(vehicle_id)->GetOrder(ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position));
|
||||
assert(order != nullptr);
|
||||
return order->GetType() == OT_CONDITIONAL;
|
||||
}
|
||||
|
||||
|
@ -141,6 +144,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
|||
if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
|
||||
|
||||
const Order *order = ::ResolveOrder(vehicle_id, order_position);
|
||||
assert(order != nullptr);
|
||||
return order->GetType() == OT_DUMMY;
|
||||
}
|
||||
|
||||
|
@ -172,6 +176,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
|||
if (order_position == ORDER_CURRENT) {
|
||||
int cur_order_pos = ::Vehicle::Get(vehicle_id)->cur_real_order_index;
|
||||
const Order *order = ::Vehicle::Get(vehicle_id)->GetFirstOrder();
|
||||
assert(order != nullptr);
|
||||
int num_implicit_orders = 0;
|
||||
for (int i = 0; i < cur_order_pos; i++) {
|
||||
if (order->GetType() == OT_IMPLICIT) num_implicit_orders++;
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
if (colour != TC_INVALID && (::TextColour)colour >= ::TC_END) return;
|
||||
|
||||
Window *w = FindWindowById((::WindowClass)window, number);
|
||||
assert(w != nullptr);
|
||||
|
||||
if (widget == WIDGET_ALL) {
|
||||
if (colour != TC_INVALID) return;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val, ModifyTimetableFlags mtf, bool timetabled)
|
||||
{
|
||||
Order *order = v->GetOrder(order_number);
|
||||
assert(order != nullptr);
|
||||
int total_delta = 0;
|
||||
int timetable_delta = 0;
|
||||
|
||||
|
@ -390,6 +391,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
|
|||
|
||||
if (v->cur_real_order_index >= v->GetNumOrders()) return;
|
||||
Order *real_current_order = v->GetOrder(v->cur_real_order_index);
|
||||
assert(real_current_order != nullptr);
|
||||
|
||||
VehicleOrderID first_manual_order = 0;
|
||||
for (Order *o = v->GetFirstOrder(); o != nullptr && o->IsType(OT_IMPLICIT); o = o->next) {
|
||||
|
|
|
@ -455,6 +455,7 @@ static std::tuple<CommandCost, uint, uint16, CargoArray> RefitVehicle(Vehicle *v
|
|||
u->cargo_subtype = result.subtype;
|
||||
if (u->type == VEH_AIRCRAFT) {
|
||||
Vehicle *w = u->Next();
|
||||
assert(w != nullptr);
|
||||
w->refit_cap = std::min<uint16>(w->refit_cap, result.mail_capacity);
|
||||
w->cargo_cap = result.mail_capacity;
|
||||
if (w->cargo.TotalCount() > w->refit_cap) w->cargo.Truncate(w->cargo.TotalCount() - w->refit_cap);
|
||||
|
|
Loading…
Reference in New Issue