mirror of
https://github.com/QB64Official/qb64.git
synced 2024-07-02 23:31:21 +00:00
Checks for array's lbound and ubound before fetching data.
This commit is contained in:
parent
d29a6657cc
commit
9aa166e4de
|
@ -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<limit) return index;
|
||||
|
|
|
@ -7,7 +7,7 @@ SUB vwatch (globalVariables AS _OFFSET, localVariables AS _OFFSET)
|
|||
STATIC AS _OFFSET vw_idehwnd
|
||||
STATIC vw_buffer$
|
||||
DIM AS LONG vw_i, vw_tempIndex, vw_localIndex, vw_varSize, vw_cmdsize
|
||||
DIM AS _OFFSET vw_address
|
||||
DIM AS _OFFSET vw_address, vw_lbound, vw_ubound
|
||||
DIM AS _MEM vw_m, vw_m2
|
||||
DIM AS _BYTE vw_isarray
|
||||
DIM vw_start!, vw_temp$, vw_cmd$, vw_value$, vw_k&, vw_buf$, vw_scope$, vw_varType$
|
||||
|
@ -19,6 +19,8 @@ SUB vwatch (globalVariables AS _OFFSET, localVariables AS _OFFSET)
|
|||
SUB unlockvWatchHandle
|
||||
SUB set_qbs_size (target AS _OFFSET, BYVAL length&)
|
||||
FUNCTION stop_program_state&
|
||||
FUNCTION check_lbound%&(array AS _OFFSET)
|
||||
FUNCTION check_ubound%&(array AS _OFFSET)
|
||||
END DECLARE
|
||||
|
||||
$IF WIN THEN
|
||||
|
@ -280,7 +282,14 @@ SUB vwatch (globalVariables AS _OFFSET, localVariables AS _OFFSET)
|
|||
vw_address = _MEMGET(vw_m, vw_address, _OFFSET) 'second resolve pass
|
||||
|
||||
IF vw_isarray THEN
|
||||
'get the address of where this array is stored
|
||||
vw_lbound = check_lbound%&(vw_address)
|
||||
vw_ubound = check_ubound%&(vw_address)
|
||||
|
||||
IF vw_arrayIndex < vw_lbound OR vw_arrayIndex > 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
|
||||
|
|
Loading…
Reference in a new issue