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 <tino.calancha@gmail.com>
This commit is contained in:
Paul Eggert 2020-06-18 14:01:56 -07:00
parent b6c7780bb0
commit fbf40c1d90

View file

@ -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)
{