shithub: choc

Download patch

ref: 77ab2ad364c5e93221a5ead1ec163a59aebf1e61
parent: f53caf73d4bd45dc4a5600c986a14af6d6bae337
author: Jessica Clarke <jrtc27@jrtc27.com>
date: Thu Jul 29 15:46:06 EDT 2021

multiplayer: Fix integer/pointer confusion

CHERI, and thus Arm's experimental Morello prototype, implements
pointers using unforgeable capabilities that include bounds and
permissions metadata to provide fine-grained spatial and referential
memory safety, as well as revocation by sweeping memory to provide heap
temporal memory safety.

The existing code did in fact work for CHERI, but was inefficient, using
a full 128-bit capability (or 64-bit on systems with a 32-bit address
space) for values that are in fact just plain ints. The only need for
intptr_t is when casting to void * for TXT_SignalConnect's user_data
argument in order to silence warnings.

--- a/src/setup/multiplayer.c
+++ b/src/setup/multiplayer.c
@@ -394,8 +394,8 @@
     const iwad_t *iwad;
     char buf[10];
     int episodes;
-    intptr_t x, y;
-    intptr_t l;
+    int x, y;
+    int l;
     int i;
 
     window = TXT_NewWindow("Select level");
@@ -424,10 +424,10 @@
                 }
 
                 M_snprintf(buf, sizeof(buf),
-                           " E%" PRIiPTR "M%" PRIiPTR " ", x, y);
+                           " E%dM%d ", x, y);
                 button = TXT_NewButton(buf);
                 TXT_SignalConnect(button, "pressed",
-                                  SetExMyWarp, (void *) (x * 10 + y));
+                                  SetExMyWarp, (void *) (intptr_t) (x * 10 + y));
                 TXT_SignalConnect(button, "pressed",
                                   CloseLevelSelectDialog, window);
                 TXT_AddWidget(window, button);
@@ -456,10 +456,10 @@
                 continue;
             }
 
-            M_snprintf(buf, sizeof(buf), " MAP%02" PRIiPTR " ", l);
+            M_snprintf(buf, sizeof(buf), " MAP%02d ", l);
             button = TXT_NewButton(buf);
             TXT_SignalConnect(button, "pressed", 
-                              SetMAPxyWarp, (void *) l);
+                              SetMAPxyWarp, (void *) (intptr_t) l);
             TXT_SignalConnect(button, "pressed",
                               CloseLevelSelectDialog, window);
             TXT_AddWidget(window, button);