summaryrefslogtreecommitdiff
path: root/libstd/bigint.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-14 03:21:03 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-14 03:21:03 -0400
commit8f2b7470799a4851a5f73e8566b18823c7fe72df (patch)
treecb1051272da3f32e0b206598705c1ddefd7b55ad /libstd/bigint.myr
parent4a59ae120acc8cbb8ee2bccbd0bcbd171f8db7b5 (diff)
downloadmc-8f2b7470799a4851a5f73e8566b18823c7fe72df.tar.gz
Fix bigint parsing for hex.
We weren't trimming the '0x' hex prefix,and that confused our code when it got the 'x' and tried to treat it as a digit.
Diffstat (limited to 'libstd/bigint.myr')
-rw-r--r--libstd/bigint.myr13
1 files changed, 9 insertions, 4 deletions
diff --git a/libstd/bigint.myr b/libstd/bigint.myr
index a0879fe..c8cdccc 100644
--- a/libstd/bigint.myr
+++ b/libstd/bigint.myr
@@ -166,7 +166,7 @@ const bigbfmt = {buf, val, base
}
const bigparse = {str
- var c, val : uint32, base
+ var c, val : int, base
var v, b
var a
@@ -179,9 +179,12 @@ const bigparse = {str
else
base = 10
;;
+ if base != 10
+ str = str[2:]
+ ;;
a = mkbigint(0)
- b = mkbigint(base castto(int32))
+ b = mkbigint(base)
/*
efficiency hack: to save allocations,
just mutate v[0]. The value will always
@@ -194,11 +197,13 @@ const bigparse = {str
continue
;;
val = charval(c, base)
- if val < 0
+ if val < 0 || val > base
bigfree(a)
+ bigfree(b)
+ bigfree(v)
-> `None
;;
- v.dig[0] = val
+ v.dig[0] = val castto(uint32)
if val == 0
v.sign = 0
else