From 7890a16d275a84910733962bf6a5c10be67a4893 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 2 Aug 2020 15:04:55 +0200 Subject: [PATCH 1/2] Fix UB in event_object_movement.c --- src/event_object_movement.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 6c49b9115..ab2f4749f 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -2340,7 +2340,13 @@ const u8 *GetObjectEventScriptPointerByObjectEventId(u8 objectEventId) static u16 GetObjectEventFlagIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup) { - return GetObjectEventTemplateByLocalIdAndMap(localId, mapNum, mapGroup)->flagId; + struct ObjectEventTemplate *obj = GetObjectEventTemplateByLocalIdAndMap(localId, mapNum, mapGroup); +#if UBFIX + // BUG: The function may return NULL, and attempting to read from NULL may freeze the game using modern compilers. + if (obj == NULL) + return 0; +#endif // UBFIX + return obj->flagId; } static u16 GetObjectEventFlagIdByObjectEventId(u8 objectEventId) From d072897354b1b2dd8619329dd965a87c2eaf52af Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 2 Aug 2020 15:37:04 +0200 Subject: [PATCH 2/2] Update event_object_movement.c --- src/event_object_movement.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index ab2f4749f..a076a2a22 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -2341,7 +2341,7 @@ const u8 *GetObjectEventScriptPointerByObjectEventId(u8 objectEventId) static u16 GetObjectEventFlagIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup) { struct ObjectEventTemplate *obj = GetObjectEventTemplateByLocalIdAndMap(localId, mapNum, mapGroup); -#if UBFIX +#ifdef UBFIX // BUG: The function may return NULL, and attempting to read from NULL may freeze the game using modern compilers. if (obj == NULL) return 0;