From ac1220c16e285131b6f23118fd7d65378409b0f6 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 18 Apr 2020 13:32:37 +0200 Subject: [PATCH] DIRECTOR: LINGO: Added helper macro for array bounds check --- engines/director/lingo/lingo-builtins.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp index 2d1502422dc..3c6dd1b81f9 100644 --- a/engines/director/lingo/lingo-builtins.cpp +++ b/engines/director/lingo/lingo-builtins.cpp @@ -52,6 +52,12 @@ namespace Director { return; \ } +#define ARRBOUNDSCHECK(idx,array) \ + if ((idx)-1 < 0 || (idx) > (array).u.farr->size()) { \ + warning("%s: index out of bounds (%d of %d)", __FUNCTION__, (idx), (array).u.farr->size()); \ + return; \ + } + static struct BuiltinProto { const char *name; void (*func)(int); @@ -645,11 +651,7 @@ void LB::b_getAt(int nargs) { TYPECHECK(index, INT); TYPECHECK(list, ARRAY); - - if (index.u.i-1 < 0 || index.u.i > list.u.farr->size()){ - warning("b_getAt: index %s out of bounds", index.type2str()); - return; - } + ARRBOUNDSCHECK(index.u.i, list); Datum result = list.u.farr->operator[](index.u.i-1); g_lingo->push(result);