summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2023-09-18 19:16:05 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2023-09-19 15:21:03 +0200
commit321f2e1e4d4b2f209b072dc891cc89cbab19f032 (patch)
tree8d5747df71c6936ed27e75b787460e10f6c415cd /src
parent7be5c8f47c9df01a5accdbf954d952b9bbe5b5f0 (diff)
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.
Diffstat (limited to 'src')
-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));
#define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
-/* untagged_ptr represents a pointer before tagging, and Lisp_Word_tag
- contains a possibly-shifted tag to be added to an untagged_ptr to
- convert it to a Lisp_Word. */
+/* Lisp_Word_tag is big enough for a possibly-shifted tag, to be
+ added to a pointer value for conversion to a Lisp_Word. */
#if LISP_WORDS_ARE_POINTERS
-/* untagged_ptr is a pointer so that the compiler knows that TAG_PTR
- yields a pointer. It is char * so that adding a tag uses simple
- machine addition. */
-typedef char *untagged_ptr;
typedef uintptr_t Lisp_Word_tag;
#else
-/* untagged_ptr is an unsigned integer instead of a pointer, so that
- it can be added to the possibly-wider Lisp_Word_tag type without
- losing information. */
-typedef uintptr_t untagged_ptr;
typedef EMACS_UINT Lisp_Word_tag;
#endif
@@ -942,7 +933,7 @@ typedef EMACS_UINT Lisp_Word_tag;
/* An initializer for a Lisp_Object that contains TAG along with PTR. */
#define TAG_PTR(tag, ptr) \
- LISP_INITIALLY ((Lisp_Word) ((untagged_ptr) (ptr) + LISP_WORD_TAG (tag)))
+ LISP_INITIALLY ((Lisp_Word) ((uintptr_t) (ptr) + LISP_WORD_TAG (tag)))
/* LISPSYM_INITIALLY (Qfoo) is equivalent to Qfoo except it is
designed for use as an initializer, even for a constant initializer. */