From d82fee7afacafa497c3ad42c7b7ff1174ac90fb0 Mon Sep 17 00:00:00 2001 From: Sang-Heon Jeon Date: Thu, 26 Sep 2019 19:23:49 +0900 Subject: [PATCH] Fix wrong int type casting with radix and larger base value Fix base value check logic when string have regex Fixed: #1408 --- tests/snippets/ints.py | 5 +++++ vm/src/obj/objint.rs | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/snippets/ints.py b/tests/snippets/ints.py index fe3d046f9..49fc8c172 100644 --- a/tests/snippets/ints.py +++ b/tests/snippets/ints.py @@ -123,6 +123,11 @@ with assert_raises(ValueError): with assert_raises(ValueError): int(b"F\xc3\xb8\xc3\xb6\xbbB\xc3\xa5r") +# string looks like radix +assert int('0b1', base=12) == 133 +assert int('0o1', base=25) == 601 +assert int('0x1', base=34) == 1123 + # underscore assert int('0xFF_FF_FF', base=16) == 16_777_215 with assert_raises(ValueError): diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index b9ea0872c..285986e0e 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -792,13 +792,16 @@ fn str_to_int(vm: &VirtualMachine, literal: &str, base: &BigInt) -> PyResult