Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55052
-- v2: vbscript: For for loop bounds coerce string to real.
From: Robert Wilhelm robert.wilhelm@gmx.net
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55052 --- dlls/vbscript/interp.c | 13 +++++++++++-- dlls/vbscript/tests/lang.vbs | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 2d979f07605..9ff6f86d28a 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -1393,7 +1393,7 @@ static HRESULT interp_step(exec_ctx_t *ctx) { const BSTR ident = ctx->instr->arg2.bstr; BOOL gteq_zero; - VARIANT zero; + VARIANT zero, end, *r; ref_t ref; HRESULT hres;
@@ -1416,7 +1416,16 @@ static HRESULT interp_step(exec_ctx_t *ctx) return E_FAIL; }
- hres = VarCmp(ref.u.v, stack_top(ctx, 1), ctx->script->lcid, 0); + r = stack_top(ctx, 1); + if (V_VT(r) == VT_BSTR) { + V_VT(&end) = VT_EMPTY; + hres = VariantChangeType(&end, stack_top(ctx, 1), 0, VT_R8); + if(FAILED(hres)) + return hres; + hres = VarCmp(ref.u.v, &end, ctx->script->lcid, 0); + } else { + hres = VarCmp(ref.u.v, stack_top(ctx, 1), ctx->script->lcid, 0); + } if(FAILED(hres)) return hres;
diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 42af6df0e76..0b9ebacec50 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -679,6 +679,29 @@ for x = 5 to 8 next Call ok(y = "for8: 5 7", "y = " & y)
+function testfor( startvalue, endvalue, stepvalue, steps) + Dim s + for x=startvalue to endvalue step stepvalue + s = s + 1 + Next + Call ok( s = steps, "counted " & s & " steps in for loop, expected " & steps) +end function + +Call testfor (1, 2, 1, 2) +Call testfor (1, "2", 1, 2) +Call testfor (1, 2, "1", 2) +Call testfor (1, "2", "1", 2) +if (isEnglishLang) then + Call testfor (1, 2, 0.5, 3) + Call testfor (1, 2.5, 0.5, 4) + Call testfor (1, "2", 0.5, 3) + Call testfor (1, "2.5", 0.5, 4) + Call testfor (1, 2, "0.5", 3) + Call testfor (1, 2.5, "0.5", 4) + Call testfor (1, "2", "0.5", 3) + Call testfor (1, "2.5", "0.5", 4) +end if + for x = 1.5 to 1 Call ok(false, "for..to called when unexpected") next