From b215ec3735b7df9d1d34c0b93013eac8dfeff89f Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 12 Aug 2024 20:43:13 +0800 Subject: [PATCH] fixes #23936; opcParseFloat accepts the wrong register as the first param [backport] (#23941) fixes #23936 follow up https://github.com/nim-lang/Nim/pull/20527 --- compiler/vm.nim | 2 +- tests/stdlib/tparseutils.nim | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler/vm.nim b/compiler/vm.nim index d27f8136e0..ea29f040dc 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1363,7 +1363,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = else: internalError(c.config, c.debug[pc], "opcParseFloat: Incorrectly created openarray") else: - regs[ra].intVal = parseBiggestFloat(regs[ra].node.strVal, rcAddr.floatVal) + regs[ra].intVal = parseBiggestFloat(regs[rb].node.strVal, rcAddr.floatVal) of opcRangeChck: let rb = instr.regB diff --git a/tests/stdlib/tparseutils.nim b/tests/stdlib/tparseutils.nim index 0209644469..b699008646 100644 --- a/tests/stdlib/tparseutils.nim +++ b/tests/stdlib/tparseutils.nim @@ -99,3 +99,14 @@ block: # With this included, static: test() crashes the compiler (from a checkParseSize " 12" , 0, 1 # Leading white # Value Edge cases checkParseSize "9223372036854775807", 19, int64.high + +block: # bug #23936 + func parsePyFloat( + a: openArray[char], # here must be openArray instead of string to reproduce this bug + res: var BiggestFloat): int = + result = parseFloat(a, res) + + static: + var f = 0.0 + doAssert "1.0".parsePyFloat(f) == 3 + doAssert f == 1.0