From: Paul Eggert Date: Thu, 18 Jun 2020 21:01:56 +0000 (-0700) Subject: Check AREF and aref_addr subscripts X-Git-Tag: emacs-28.0.90~7141 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fbf40c1d903d18286ecd7d2c1d7b117c88a1d5dd;p=emacs.git Check AREF and aref_addr subscripts * src/lisp.h (gc_asize): Move before first use. (AREF, aref_addr): Check subscripts. Co-authored-by: Tino Calancha --- diff --git a/src/lisp.h b/src/lisp.h index 34426990882..7b4f484b9b7 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -1671,6 +1671,13 @@ ASIZE (Lisp_Object array) return size; } +INLINE ptrdiff_t +gc_asize (Lisp_Object array) +{ + /* Like ASIZE, but also can be used in the garbage collector. */ + return XVECTOR (array)->header.size & ~ARRAY_MARK_FLAG; +} + INLINE ptrdiff_t PVSIZE (Lisp_Object pv) { @@ -1853,22 +1860,17 @@ bool_vector_set (Lisp_Object a, EMACS_INT i, bool b) INLINE Lisp_Object AREF (Lisp_Object array, ptrdiff_t idx) { + eassert (0 <= idx && idx < gc_asize (array)); return XVECTOR (array)->contents[idx]; } INLINE Lisp_Object * aref_addr (Lisp_Object array, ptrdiff_t idx) { + eassert (0 <= idx && idx <= gc_asize (array)); return & XVECTOR (array)->contents[idx]; } -INLINE ptrdiff_t -gc_asize (Lisp_Object array) -{ - /* Like ASIZE, but also can be used in the garbage collector. */ - return XVECTOR (array)->header.size & ~ARRAY_MARK_FLAG; -} - INLINE void ASET (Lisp_Object array, ptrdiff_t idx, Lisp_Object val) {