Check for null pointers in several places in the search plugin

Fixes #650 (and a few other potential issues)
develop
lethosor 2015-06-30 16:18:27 -04:00
parent 95e04ef56a
commit 8058472dd9
2 changed files with 15 additions and 0 deletions

@ -25,6 +25,7 @@ DFHack Future
Fixed default arguments in Lua gametype detection functions Fixed default arguments in Lua gametype detection functions
gui/hack-wish now properly assigns quality to items. gui/hack-wish now properly assigns quality to items.
gui/gm-editor handles lua tables properly gui/gm-editor handles lua tables properly
search: fixed crash in unit list after cancelling a job
steam-engine: fixed a crash on arena load steam-engine: fixed a crash on arena load
tweak fps-min fixed tweak fps-min fixed
workflow: Fixed some issues with stuck jobs workflow: Fixed some issues with stuck jobs

@ -102,6 +102,8 @@ static bool is_live_screen(const df::viewscreen *screen)
static string get_unit_description(df::unit *unit) static string get_unit_description(df::unit *unit)
{ {
if (!unit)
return "";
string desc; string desc;
auto name = Units::getVisibleName(unit); auto name = Units::getVisibleName(unit);
if (name->has_name) if (name->has_name)
@ -954,6 +956,8 @@ private:
private: private:
string get_element_description(df::item *element) const string get_element_description(df::item *element) const
{ {
if (!element)
return "";
return Items::getDescription(element, 0, true); return Items::getDescription(element, 0, true);
} }
@ -989,6 +993,8 @@ private:
static string get_non_work_description(df::unit *unit) static string get_non_work_description(df::unit *unit)
{ {
if (!unit)
return "";
for (auto p = unit->status.misc_traits.begin(); p < unit->status.misc_traits.end(); p++) for (auto p = unit->status.misc_traits.begin(); p < unit->status.misc_traits.end(); p++)
{ {
if ((*p)->id == misc_trait_type::Migrant || (*p)->id == misc_trait_type::OnBreak) if ((*p)->id == misc_trait_type::Migrant || (*p)->id == misc_trait_type::OnBreak)
@ -1013,6 +1019,8 @@ private:
string get_element_description(df::unit *unit) const string get_element_description(df::unit *unit) const
{ {
if (!unit)
return "Inactive";
string desc = get_unit_description(unit); string desc = get_unit_description(unit);
if (!unit->job.current_job) if (!unit->job.current_job)
{ {
@ -1080,6 +1088,8 @@ class trade_search_base : public search_twocolumn_modifiable<df::viewscreen_trad
private: private:
string get_element_description(df::item *element) const string get_element_description(df::item *element) const
{ {
if (!element)
return "";
return Items::getDescription(element, 0, true); return Items::getDescription(element, 0, true);
} }
@ -1355,6 +1365,8 @@ private:
string get_element_description(df::building *bld) const string get_element_description(df::building *bld) const
{ {
if (!bld)
return "";
bool is_ownable_room = (bld->is_room && room_quality_names.find(bld->getType()) != room_quality_names.end()); bool is_ownable_room = (bld->is_room && room_quality_names.find(bld->getType()) != room_quality_names.end());
string desc; string desc;
@ -1443,6 +1455,8 @@ private:
private: private:
string get_element_description(df::report *element) const string get_element_description(df::report *element) const
{ {
if (!element)
return "";
return element->text; return element->text;
} }
}; };