aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias EngdegÄrd2023-08-28 11:13:10 +0200
committerMattias EngdegÄrd2023-09-18 20:06:01 +0200
commit861f9cb78370e2b78f852e5ccde9b63c94486ca8 (patch)
tree212ba6f4cf9d1df5ba6887a322e79cbb0d0f10cb /src
parent146bd41ddef21a19634e2b90db4bfb619a2091b2 (diff)
downloademacs-861f9cb78370e2b78f852e5ccde9b63c94486ca8.tar.gz
emacs-861f9cb78370e2b78f852e5ccde9b63c94486ca8.zip
Don't use pointer arithmetic for untagging Lisp values (bug#65491)
* src/lisp.h (XUNTAG): Instead of casting a Lisp value to char * and subtracting the tag, cast it to a suitable integral type and work on that. This should result in identical or at least equivalent code, except that it avoids potential problems arising from the restrictions on pointer arithmetic in C. In particular, a null pointer can be neither an operand in nor the result of pointer arithmetic. C compilers know this and would, prior to this change, optimise XUNTAG(obj, Lisp_Int0, mytype) != NULL to 1. This means, for example, that make_pointer_integer and XFIXNUMPTR could not be entrusted with null pointers, and next_vector in alloc.c was unsafe to use.
Diffstat (limited to 'src')
-rw-r--r--src/lisp.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lisp.h b/src/lisp.h
index 50b68f2e767..de6746f1c07 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -808,10 +808,12 @@ INLINE void
808} 808}
809 809
810/* Extract A's pointer value, assuming A's Lisp type is TYPE and the 810/* Extract A's pointer value, assuming A's Lisp type is TYPE and the
811 extracted pointer's type is CTYPE *. */ 811 extracted pointer's type is CTYPE *.
812 812 Note that the second term vanishes if EMACS_INT is wider than pointers
813#define XUNTAG(a, type, ctype) ((ctype *) \ 813 and the tag is in the upper bits (ie, USE_LSB_TAG=0); this makes
814 ((char *) XLP (a) - LISP_WORD_TAG (type))) 814 untagging slightly cheaper in that case. */
815#define XUNTAG(a, type, ctype) \
816 ((ctype *) ((uintptr_t) XLP (a) - (uintptr_t) LISP_WORD_TAG (type)))
815 817
816/* A forwarding pointer to a value. It uses a generic pointer to 818/* A forwarding pointer to a value. It uses a generic pointer to
817 avoid alignment bugs that could occur if it used a pointer to a 819 avoid alignment bugs that could occur if it used a pointer to a