aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2023-09-18 19:16:05 +0200
committerMattias EngdegÄrd2023-09-19 15:21:03 +0200
commit321f2e1e4d4b2f209b072dc891cc89cbab19f032 (patch)
tree8d5747df71c6936ed27e75b787460e10f6c415cd
parent7be5c8f47c9df01a5accdbf954d952b9bbe5b5f0 (diff)
downloademacs-321f2e1e4d4b2f209b072dc891cc89cbab19f032.tar.gz
emacs-321f2e1e4d4b2f209b072dc891cc89cbab19f032.zip
Don't use pointer arithmetic for pointer tagging (bug#65491)
This makes for safer code when tagging null pointers in particular, since pointer arithmetic on NULL is undefined and therefore can be assumed, by the compiler, not to occur. * src/lisp.h (untagged_ptr): Remove. (TAG_PTR): Cast to uintptr_t instead of untagged_ptr.
-rw-r--r--src/lisp.h15
1 files changed, 3 insertions, 12 deletions
diff --git a/src/lisp.h b/src/lisp.h
index 79ce8e5fa8e..39aa51531fe 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -919,20 +919,11 @@ verify (GCALIGNED (struct Lisp_Symbol));
919#define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \ 919#define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
920 Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object) 920 Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
921 921
922/* untagged_ptr represents a pointer before tagging, and Lisp_Word_tag 922/* Lisp_Word_tag is big enough for a possibly-shifted tag, to be
923 contains a possibly-shifted tag to be added to an untagged_ptr to 923 added to a pointer value for conversion to a Lisp_Word. */
924 convert it to a Lisp_Word. */
925#if LISP_WORDS_ARE_POINTERS 924#if LISP_WORDS_ARE_POINTERS
926/* untagged_ptr is a pointer so that the compiler knows that TAG_PTR
927 yields a pointer. It is char * so that adding a tag uses simple
928 machine addition. */
929typedef char *untagged_ptr;
930typedef uintptr_t Lisp_Word_tag; 925typedef uintptr_t Lisp_Word_tag;
931#else 926#else
932/* untagged_ptr is an unsigned integer instead of a pointer, so that
933 it can be added to the possibly-wider Lisp_Word_tag type without
934 losing information. */
935typedef uintptr_t untagged_ptr;
936typedef EMACS_UINT Lisp_Word_tag; 927typedef EMACS_UINT Lisp_Word_tag;
937#endif 928#endif
938 929
@@ -942,7 +933,7 @@ typedef EMACS_UINT Lisp_Word_tag;
942 933
943/* An initializer for a Lisp_Object that contains TAG along with PTR. */ 934/* An initializer for a Lisp_Object that contains TAG along with PTR. */
944#define TAG_PTR(tag, ptr) \ 935#define TAG_PTR(tag, ptr) \
945 LISP_INITIALLY ((Lisp_Word) ((untagged_ptr) (ptr) + LISP_WORD_TAG (tag))) 936 LISP_INITIALLY ((Lisp_Word) ((uintptr_t) (ptr) + LISP_WORD_TAG (tag)))
946 937
947/* LISPSYM_INITIALLY (Qfoo) is equivalent to Qfoo except it is 938/* LISPSYM_INITIALLY (Qfoo) is equivalent to Qfoo except it is
948 designed for use as an initializer, even for a constant initializer. */ 939 designed for use as an initializer, even for a constant initializer. */