Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Jun 2021 17:31:24 GMT
From:      Jessica Clarke <jrtc27@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: de295884c4ef - main - tip: Cast via intptr_t not long when casting between pointer and int
Message-ID:  <202106081731.158HVO7d035986@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jrtc27:

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

commit de295884c4efd9a126dfdd8d98247de345d1f468
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2021-06-08 17:30:59 +0000
Commit:     Jessica Clarke <jrtc27@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)
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106081731.158HVO7d035986>