aboutsummaryrefslogtreecommitdiff
path: root/games/abuse/fix-startup-segfault.diff
blob: 47a675acfb43d0d1bddc2cf4f8bbd7fc36dcf004 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
diff -Naur abuse-0.8/src/lisp/lisp.cpp abuse-0.8.patched/src/lisp/lisp.cpp
--- abuse-0.8/src/lisp/lisp.cpp	2011-05-02 07:55:06.000000000 -0400
+++ abuse-0.8.patched/src/lisp/lisp.cpp	2023-08-07 20:52:41.197394085 -0400
@@ -867,7 +867,7 @@
     size_t ret = 0;
 
 #ifdef TYPE_CHECKING
-    if (this && item_type(this) != (ltype)L_CONS_CELL)
+    if (item_type(this) != (ltype)L_CONS_CELL)
     {
         Print();
         lbreak(" is not a sequence\n");
@@ -1275,7 +1275,7 @@
     switch (item_type(this))
     {
     case L_CONS_CELL:
-        if (!this)
+        if (ptr_is_null(this))
         {
             lprint_string("nil");
         }
@@ -3080,7 +3080,7 @@
 
     LObject *ret = NULL;
 
-    if (this)
+    if (!ptr_is_null(this))
     {
         switch (item_type(this))
         {
diff -Naur abuse-0.8/src/lisp/lisp.h abuse-0.8.patched/src/lisp/lisp.h
--- abuse-0.8/src/lisp/lisp.h	2011-05-02 07:55:06.000000000 -0400
+++ abuse-0.8.patched/src/lisp/lisp.h	2023-08-07 20:53:56.765386973 -0400
@@ -201,7 +201,28 @@
 
 static inline LObject *&CAR(void *x) { return ((LList *)x)->car; }
 static inline LObject *&CDR(void *x) { return ((LList *)x)->cdr; }
-static inline ltype item_type(void *x) { if (x) return *(ltype *)x; return L_CONS_CELL; }
+
+#ifdef __GNUC__
+/*
+ * C++ spec says "this" is always NON-NULL, recent versions of gcc will warn
+ * about this and optimizes the "if (this)" we use in some places away:
+ * "warning: nonnull argument ‘this’ compared to NULL [-Wnonnull-compare]"
+ * We rely on "if (this)" checks in several places and refactoring this is
+ * non trivial. So we use this little helper marked with
+ * __attribute__((optimize("O0"))) to workaround this.
+ */
+static inline bool __attribute__((optimize("O0"))) ptr_is_null(void *ptr)
+{
+    return ptr == NULL;
+}
+#else
+static inline bool ptr_is_null(void *ptr)
+{
+    return ptr == NULL;
+}
+#endif
+
+static inline ltype item_type(void *x) { if (!ptr_is_null(x)) return *(ltype *)x; return L_CONS_CELL; }
 
 void perm_space();
 void tmp_space();