Move null pointer check from Job module to LuaApi, where it does not invoke undefined behavior.

develop
Ben Lubar 2018-04-05 16:01:26 -05:00
parent 91930a618f
commit a44b3b8f98
No known key found for this signature in database
GPG Key ID: 018BAB45DB2D2B24
2 changed files with 12 additions and 8 deletions

@ -1504,8 +1504,18 @@ static const luaL_Reg dfhack_gui_funcs[] = {
/***** Job module *****/ /***** Job module *****/
static bool jobEqual(df::job *job1, df::job *job2) { return *job1 == *job2; } static bool jobEqual(const df::job *job1, const df::job *job2)
static bool jobItemEqual(df::job_item *job1, df::job_item *job2) { return *job1 == *job2; } {
CHECK_NULL_POINTER(job1);
CHECK_NULL_POINTER(job2);
return *job1 == *job2;
}
static bool jobItemEqual(const df::job_item *job1, const df::job_item *job2)
{
CHECK_NULL_POINTER(job1);
CHECK_NULL_POINTER(job2);
return *job1 == *job2;
}
static const LuaWrapper::FunctionReg dfhack_job_module[] = { static const LuaWrapper::FunctionReg dfhack_job_module[] = {
WRAPM(Job,cloneJobStruct), WRAPM(Job,cloneJobStruct),

@ -129,9 +129,6 @@ void DFHack::Job::deleteJobStruct(df::job *job, bool keptEverything)
bool DFHack::operator== (const df::job_item &a, const df::job_item &b) bool DFHack::operator== (const df::job_item &a, const df::job_item &b)
{ {
CHECK_NULL_POINTER(&a);
CHECK_NULL_POINTER(&b);
if (!(CMP(item_type) && CMP(item_subtype) && if (!(CMP(item_type) && CMP(item_subtype) &&
CMP(mat_type) && CMP(mat_index) && CMP(mat_type) && CMP(mat_index) &&
CMP(flags1.whole) && CMP(quantity) && CMP(vector_id) && CMP(flags1.whole) && CMP(quantity) && CMP(vector_id) &&
@ -152,9 +149,6 @@ bool DFHack::operator== (const df::job_item &a, const df::job_item &b)
bool DFHack::operator== (const df::job &a, const df::job &b) bool DFHack::operator== (const df::job &a, const df::job &b)
{ {
CHECK_NULL_POINTER(&a);
CHECK_NULL_POINTER(&b);
if (!(CMP(job_type) && CMP(job_subtype) && if (!(CMP(job_type) && CMP(job_subtype) &&
CMP(mat_type) && CMP(mat_index) && CMP(mat_type) && CMP(mat_index) &&
CMP(item_subtype) && CMP(item_category.whole) && CMP(item_subtype) && CMP(item_category.whole) &&