summaryrefslogtreecommitdiff
path: root/include/global.h
diff options
context:
space:
mode:
authorGriffinR <griffin.g.richards@gmail.com>2021-07-03 17:25:05 -0400
committerGitHub <noreply@github.com>2021-07-03 17:25:05 -0400
commit585d92f298e1edd8f756f8362de45c9fadc6fcab (patch)
tree2e3b17d37c4782f575329fc0fbe1f7bd406e6bad /include/global.h
parent558097f42326f19044a6351004468a46d6ee0b38 (diff)
parentff94d49a45ef605cfaed1268aa5a230958e25cd9 (diff)
Merge pull request #445 from Kurausukun/ubfix
Port UBFIX Macro and Some Usages from Emerald
Diffstat (limited to 'include/global.h')
-rw-r--r--include/global.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/global.h b/include/global.h
index 1d12fdae9..f7abcc23d 100644
--- a/include/global.h
+++ b/include/global.h
@@ -73,6 +73,14 @@
#define abs(x) (((x) < 0) ? -(x) : (x))
#endif
+// Used in cases where division by 0 can occur in the retail version.
+// Avoids invalid opcodes on some emulators, and the otherwise UB.
+#ifdef UBFIX
+#define SAFE_DIV(a, b) ((b) ? (a) / (b) : 0)
+#else
+#define SAFE_DIV(a, b) ((a) / (b))
+#endif
+
// There are many quirks in the source code which have overarching behavioral differences from
// a number of other files. For example, diploma.c seems to declare rodata before each use while
// other files declare out of order and must be at the beginning. There are also a number of