foxygit / doom Log in
commit 77ab2ad364c5e93221a5ead1ec163a59aebf1e61
Author:     Jessica Clarke <jrtc27@jrtc27.com>
AuthorDate: Thu Jul 29 19:46:06 2021 +0100
Commit:     Jessica Clarke <jrtc27@jrtc27.com>
CommitDate: Thu Jul 29 19:49:20 2021 +0100

    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.
---
 src/setup/multiplayer.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/setup/multiplayer.c b/src/setup/multiplayer.c
index 860a644d..02e50c03 100644
--- a/src/setup/multiplayer.c
+++ b/src/setup/multiplayer.c
@@ -394,8 +394,8 @@ static void LevelSelectDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(user_data))
     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 @@ static void LevelSelectDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(user_data))
                 }

                 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 @@ static void LevelSelectDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(user_data))
                 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);