git: de295884c4ef - main - tip: Cast via intptr_t not long when casting between pointer and int

Jessica Clarke jrtc27 at FreeBSD.org
Tue Jun 8 17:31:25 UTC 2021


The branch main has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=de295884c4efd9a126dfdd8d98247de345d1f468

commit de295884c4efd9a126dfdd8d98247de345d1f468
Author:     Jessica Clarke <jrtc27 at FreeBSD.org>
AuthorDate: 2021-06-08 17:30:59 +0000
Commit:     Jessica Clarke <jrtc27 at FreeBSD.org>
CommitDate: 2021-06-08 17:30:59 +0000

    tip: Cast via intptr_t not long when casting between pointer and int
    
    Whilst all FreeBSD architectures have the same representation for
    intptr_t and long (even if the former is int on ILP32 architectures),
    this is more general and correct, and on CHERI they are not the same so
    warnings are generated by default for integer-to-pointer casts that
    aren't via (u)intptr_t.
    
    Reviewed by:    imp, kib
    Obtained from:  CheriBSD
    Differential Revision:  https://reviews.freebsd.org/D30696
---
 usr.bin/tip/tip/tip.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/usr.bin/tip/tip/tip.h b/usr.bin/tip/tip/tip.h
index ab6b2c4cd9a0..6bf94521cdfd 100644
--- a/usr.bin/tip/tip/tip.h
+++ b/usr.bin/tip/tip/tip.h
@@ -153,16 +153,16 @@ typedef
  */
 
 #define value(v)	vtable[v].v_value
-#define lvalue(v)	(long)vtable[v].v_value
+#define lvalue(v)	(long)(intptr_t)vtable[v].v_value
 
-#define	number(v)	((long)(v))
-#define	boolean(v)      ((short)(long)(v))
-#define	character(v)    ((char)(long)(v))
-#define	address(v)      ((long *)(v))
+#define	number(v)	((long)(intptr_t)(v))
+#define	boolean(v)	((short)(intptr_t)(v))
+#define	character(v)	((char)(intptr_t)(v))
+#define	address(v)	((long *)(v))
 
-#define	setnumber(v,n)		do { (v) = (char *)(long)(n); } while (0)
-#define	setboolean(v,n)		do { (v) = (char *)(long)(n); } while (0)
-#define	setcharacter(v,n)	do { (v) = (char *)(long)(n); } while (0)
+#define	setnumber(v,n)		do { (v) = (char *)(intptr_t)(n); } while (0)
+#define	setboolean(v,n)		do { (v) = (char *)(intptr_t)(n); } while (0)
+#define	setcharacter(v,n)	do { (v) = (char *)(intptr_t)(n); } while (0)
 #define	setaddress(v,n)		do { (v) = (char *)(n); } while (0)
 
 /*


More information about the dev-commits-src-main mailing list