Tcl Source Code

Artifact [9aa859a6b6]
Login

Artifact 9aa859a6b6335d0c868e9eaa3721d031c4c3baf526285b1eacc14005fd87aac1:

Attachment "0001-generic-tclCompile.h-TclGet-Int-AtPtr-Fix-casts.patch" to ticket [26f1328a86] added by anonymous 2022-01-07 16:14:06. (unpublished)
From 28df47595eea893a02c947f89daf371f134c3553 Mon Sep 17 00:00:00 2001
From: Benjamin Riefenstahl <[email protected]>
Date: Sun, 28 Nov 2021 21:52:50 +0100
Subject: [PATCH] generic/tclCompile.h (TclGet*Int*AtPtr): Fix casts.

Plan 9 on x64 is a system where sizeof ptr == 8 and sizeof int == 4.
Under those circumstances a negative int converted to an unsigned is
not good as a pointer offset.  Therefore it is crucial that the result
of TclGetInt1AtPtr is actually a signed int and not unsigned (as it
was before, because int|unsigned -> unsigned|unsigned -> unsigned).
Fix the other adjacent macros in the same way.
---
 generic/tclCompile.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/generic/tclCompile.h b/generic/tclCompile.h
index 96a354103..30b364daf 100644
--- a/generic/tclCompile.h
+++ b/generic/tclCompile.h
@@ -1495,22 +1495,22 @@ MODULE_SCOPE int	TclPushProcCallFrame(void *clientData,
 #   define TclGetInt1AtPtr(p) ((int) *((signed char *) p))
 #else
 #   define TclGetInt1AtPtr(p) \
-    (((int) *((char *) p)) | ((*(p) & 0200) ? (-256) : 0))
+    ((int) ((*((char *) p)) | ((*(p) & 0200) ? (-256) : 0)))
 #endif
 
 #define TclGetInt4AtPtr(p) \
-    (((int) (TclGetUInt1AtPtr(p) << 24)) |				\
-		     (*((p)+1) << 16) |				\
-		     (*((p)+2) <<  8) |				\
-		     (*((p)+3)))
+    ((int) ((TclGetUInt1AtPtr(p) << 24) |			\
+		       (*((p)+1) << 16) |			\
+		       (*((p)+2) <<  8) |			\
+		       (*((p)+3))))
 
 #define TclGetUInt1AtPtr(p) \
     ((unsigned int) *(p))
 #define TclGetUInt4AtPtr(p) \
-    ((unsigned int) (*(p)     << 24) |				\
-		    (*((p)+1) << 16) |				\
-		    (*((p)+2) <<  8) |				\
-		    (*((p)+3)))
+    ((unsigned int) ((*(p)     << 24) |				\
+		     (*((p)+1) << 16) |				\
+		     (*((p)+2) <<  8) |				\
+		     (*((p)+3))))
 
 /*
  * Macros used to compute the minimum and maximum of two integers. The ANSI C
-- 
2.30.2