From 9aa166e4debd8e639e39cb366320dce686fd8fa7 Mon Sep 17 00:00:00 2001 From: FellippeHeitor Date: Thu, 19 Aug 2021 19:10:51 -0300 Subject: [PATCH] Checks for array's lbound and ubound before fetching data. --- internal/c/qbx.cpp | 8 ++++++++ internal/support/vwatch/vwatch.bm | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/c/qbx.cpp b/internal/c/qbx.cpp index 055b79d88..fba71478f 100755 --- a/internal/c/qbx.cpp +++ b/internal/c/qbx.cpp @@ -941,6 +941,14 @@ inline int16 func_abs(int16 d){return abs(d);} inline int32 func_abs(int32 d){return abs(d);} inline int64 func_abs(int64 d){return llabs(d);} +ptrszint check_lbound(ptrszint *array) { + return func_lbound((ptrszint*)(*array),1,1); +} + +ptrszint check_ubound(ptrszint *array) { + return func_ubound((ptrszint*)(*array),1,1); +} + inline ptrszint array_check(uptrszint index,uptrszint limit){ //nb. forces signed index into an unsigned variable for quicker comparison if (index vw_ubound THEN + GOTO cmdProcessingDone + END IF + + 'get the address of where this array's data is stored vw_buf$ = SPACE$(LEN(vw_dummy%&)) vw_m = _MEM(vw_address, LEN(vw_dummy%&)) vw_m2 = _MEM(_OFFSET(vw_buf$), LEN(vw_dummy%&)) @@ -301,7 +310,7 @@ SUB vwatch (globalVariables AS _OFFSET, localVariables AS _OFFSET) END IF 'this is where we calculate the actual element position in memory - vw_address = vw_address + ((vw_arrayIndex - 1) * vw_varSize) + vw_address = vw_address + ((vw_arrayIndex - vw_lbound) * vw_varSize) END IF 'vw_address now points to the actual data