summaryrefslogtreecommitdiff
path: root/src/emacs-module.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-04-01 01:24:55 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2016-04-01 01:25:14 -0700
commit423d6a6156cea32757f13277e31a5867aec12dca (patch)
tree104abc47b8cd5da1caac4fc026fa99f8bfcd347b /src/emacs-module.c
parent750e1e19429cd781e2e60b462d19ef827d4da943 (diff)
downloademacs-423d6a6156cea32757f13277e31a5867aec12dca.tar.gz
Fix check for subscript errors in module calls
* src/emacs-module.c (check_vec_index): New function. (module_vec_set, module_vec_get): Use it instead of a not-strict-enough check.
Diffstat (limited to 'src/emacs-module.c')
-rw-r--r--src/emacs-module.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index f9ede84ed17..b57636e54e5 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -588,13 +588,21 @@ module_set_user_finalizer (emacs_env *env, emacs_value uptr,
}
static void
+check_vec_index (Lisp_Object lvec, ptrdiff_t i)
+{
+ CHECK_VECTOR (lvec);
+ if (! (0 <= i && i < ASIZE (lvec)))
+ args_out_of_range_3 (make_fixnum_or_float (i),
+ make_number (0), make_number (ASIZE (lvec) - 1));
+}
+
+static void
module_vec_set (emacs_env *env, emacs_value vec, ptrdiff_t i, emacs_value val)
{
/* FIXME: This function should return bool because it can fail. */
MODULE_FUNCTION_BEGIN ();
Lisp_Object lvec = value_to_lisp (vec);
- CHECK_VECTOR (lvec);
- CHECK_RANGED_INTEGER (make_number (i), 0, ASIZE (lvec) - 1);
+ check_vec_index (lvec, i);
ASET (lvec, i, value_to_lisp (val));
}
@@ -603,8 +611,7 @@ module_vec_get (emacs_env *env, emacs_value vec, ptrdiff_t i)
{
MODULE_FUNCTION_BEGIN (module_nil);
Lisp_Object lvec = value_to_lisp (vec);
- CHECK_VECTOR (lvec);
- CHECK_RANGED_INTEGER (make_number (i), 0, ASIZE (lvec) - 1);
+ check_vec_index (lvec, i);
return lisp_to_value (AREF (lvec, i));
}