Skip to content

Commit a44b3b8

Browse files
committed
Move null pointer check from Job module to LuaApi, where it does not invoke undefined behavior.
1 parent 91930a6 commit a44b3b8

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

library/LuaApi.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,8 +1504,18 @@ static const luaL_Reg dfhack_gui_funcs[] = {
15041504

15051505
/***** Job module *****/
15061506

1507-
static bool jobEqual(df::job *job1, df::job *job2) { return *job1 == *job2; }
1508-
static bool jobItemEqual(df::job_item *job1, df::job_item *job2) { return *job1 == *job2; }
1507+
static bool jobEqual(const df::job *job1, const df::job *job2)
1508+
{
1509+
CHECK_NULL_POINTER(job1);
1510+
CHECK_NULL_POINTER(job2);
1511+
return *job1 == *job2;
1512+
}
1513+
static bool jobItemEqual(const df::job_item *job1, const df::job_item *job2)
1514+
{
1515+
CHECK_NULL_POINTER(job1);
1516+
CHECK_NULL_POINTER(job2);
1517+
return *job1 == *job2;
1518+
}
15091519

15101520
static const LuaWrapper::FunctionReg dfhack_job_module[] = {
15111521
WRAPM(Job,cloneJobStruct),

library/modules/Job.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ void DFHack::Job::deleteJobStruct(df::job *job, bool keptEverything)
129129

130130
bool DFHack::operator== (const df::job_item &a, const df::job_item &b)
131131
{
132-
CHECK_NULL_POINTER(&a);
133-
CHECK_NULL_POINTER(&b);
134-
135132
if (!(CMP(item_type) && CMP(item_subtype) &&
136133
CMP(mat_type) && CMP(mat_index) &&
137134
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)
152149

153150
bool DFHack::operator== (const df::job &a, const df::job &b)
154151
{
155-
CHECK_NULL_POINTER(&a);
156-
CHECK_NULL_POINTER(&b);
157-
158152
if (!(CMP(job_type) && CMP(job_subtype) &&
159153
CMP(mat_type) && CMP(mat_index) &&
160154
CMP(item_subtype) && CMP(item_category.whole) &&

0 commit comments

Comments
 (0)