Fix some crashes on self-modifying Elisp code
commit93511e94735de5862880f5ea9bf12705c1440363
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 6 Aug 2017 23:57:08 +0000 (6 16:57 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 6 Aug 2017 23:58:35 +0000 (6 16:58 -0700)
tree8c02753b243688359639e31ed215bc25a19813af
parent8a406d1185b6c87f6647c141a1cc06786cd9480d
Fix some crashes on self-modifying Elisp code

Prompted by a problem report by Alex in:
http://lists.gnu.org/archive/html/emacs-devel/2017-08/msg00143.html
* src/eval.c (For, Fprogn, Fsetq, FletX, eval_sub):
Compute XCDR (x) near XCAR (x); although this doesn't fix any bugs,
it is likely to run a bit faster with typical hardware caches.
(Fif): Use Fcdr instead of XCDR, to avoid crashing on
self-modifying S-expressions.
(Fsetq, Flet, eval_sub): Count the number of arguments as we go
instead of trusting an Flength prepass, to avoid problems when the
code is self-modifying.
(Fquote, Ffunction, Fdefvar, Fdefconst): Prefer !NILP to CONSP
where either will do.  This is mostly to document the fact that
the value must be a proper list.  It's also a tiny bit faster on
typical machines nowadays.
(Fdefconst, FletX): Prefer XCAR+XCDR to Fcar+Fcdr when either will do.
(eval_sub): Check that the args are a list as opposed to some
other object that has a length. This prevents e.g. (if . "string")
from making Emacs dump core in some cases.
* test/src/eval-tests.el (eval-tests--if-dot-string)
(eval-tests--let-with-circular-defs, eval-tests--mutating-cond):
New tests.
src/eval.c
test/src/eval-tests.el