From 0b5473c166d0fca9c71080e688c85a6580c4cb0f Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Tue, 10 Oct 2017 17:08:46 +0200 Subject: [PATCH] vbscript: Reimplement array_access function. Signed-off-by: Piotr Caban Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/vbscript/interp.c | 55 ++++++++++++++++++------------------ dlls/vbscript/tests/lang.vbs | 2 ++ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 02180d91dcc..feb8119086c 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -481,10 +481,8 @@ static void vbstack_to_dp(exec_ctx_t *ctx, unsigned arg_cnt, BOOL is_propput, DI static HRESULT array_access(exec_ctx_t *ctx, SAFEARRAY *array, DISPPARAMS *dp, VARIANT **ret) { - unsigned cell_off = 0, dim_size = 1, i; - unsigned argc = arg_cnt(dp); - VARIANT *data; - LONG idx; + unsigned i, argc = arg_cnt(dp); + LONG *indices; HRESULT hres; if(!array) { @@ -492,34 +490,35 @@ static HRESULT array_access(exec_ctx_t *ctx, SAFEARRAY *array, DISPPARAMS *dp, V return E_FAIL; } - if(array->cDims != argc) { - FIXME("argc %d does not match cDims %d\n", dp->cArgs, array->cDims); - return E_FAIL; - } - - for(i=0; i < argc; i++) { - hres = to_int(get_arg(dp, i), &idx); - if(FAILED(hres)) - return hres; - - idx -= array->rgsabound[i].lLbound; - if(idx >= array->rgsabound[i].cElements) { - FIXME("out of bound element %d in dim %d of size %d\n", idx, i+1, array->rgsabound[i].cElements); - return E_FAIL; - } - - cell_off += idx*dim_size; - dim_size *= array->rgsabound[i].cElements; - } - - hres = SafeArrayAccessData(array, (void**)&data); + hres = SafeArrayLock(array); if(FAILED(hres)) return hres; - *ret = data+cell_off; + if(array->cDims != argc) { + FIXME("argc %d does not match cDims %d\n", dp->cArgs, array->cDims); + SafeArrayUnlock(array); + return E_FAIL; + } - SafeArrayUnaccessData(array); - return S_OK; + indices = heap_alloc(sizeof(*indices) * argc); + if(!indices) { + SafeArrayUnlock(array); + return E_OUTOFMEMORY; + } + + for(i=0; i