aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2018-01-17 16:15:33 +0100
committerLukas Larsson <[email protected]>2018-01-17 16:15:33 +0100
commit919b6ddc24e409ec78380af14511ad50a88b4525 (patch)
treeb88c5b958e41944f777d4f05d6eb8254a6f927ea /erts
parentb5f2a0703882d919e15a0ca2e24616aa97033a77 (diff)
parent434e4774a4f7e70437ee8a50c7b99ff3bda67282 (diff)
downloadotp-919b6ddc24e409ec78380af14511ad50a88b4525.tar.gz
otp-919b6ddc24e409ec78380af14511ad50a88b4525.tar.bz2
otp-919b6ddc24e409ec78380af14511ad50a88b4525.zip
Merge branch 'fhunleth/binary_to_integer_chec/PR-1671/OTP-14879' into maint
* fhunleth/binary_to_integer_chec/PR-1671/OTP-14879: Fail if ':' is passed to binary_to_integer/2
Diffstat (limited to 'erts')
-rw-r--r--erts/emulator/beam/big.c15
-rw-r--r--erts/emulator/test/num_bif_SUITE.erl2
2 files changed, 11 insertions, 6 deletions
diff --git a/erts/emulator/beam/big.c b/erts/emulator/beam/big.c
index 5eaf262cd8..c5cb268f09 100644
--- a/erts/emulator/beam/big.c
+++ b/erts/emulator/beam/big.c
@@ -2549,12 +2549,17 @@ int term_equals_2pow32(Eterm x)
}
}
+static ERTS_INLINE int c2int_is_valid_char(byte ch, int base) {
+ if (base <= 10)
+ return (ch >= '0' && ch < ('0' + base));
+ else
+ return (ch >= '0' && ch <= '9')
+ || (ch >= 'A' && ch < ('A' + base - 10))
+ || (ch >= 'a' && ch < ('a' + base - 10));
+}
+
static ERTS_INLINE int c2int_is_invalid_char(byte ch, int base) {
- return (ch < '0'
- || (ch > ('0' + base - 1)
- && !(base > 10
- && ((ch >= 'a' && ch < ('a' + base - 10))
- || (ch >= 'A' && ch < ('A' + base - 10))))));
+ return !c2int_is_valid_char(ch, base);
}
static ERTS_INLINE byte c2int_digit_from_base(byte ch) {
diff --git a/erts/emulator/test/num_bif_SUITE.erl b/erts/emulator/test/num_bif_SUITE.erl
index 1c76eb8019..ac1a667185 100644
--- a/erts/emulator/test/num_bif_SUITE.erl
+++ b/erts/emulator/test/num_bif_SUITE.erl
@@ -491,7 +491,7 @@ t_string_to_integer(Config) when is_list(Config) ->
list_to_binary(Value),Base)),
{'EXIT', {badarg, _}} =
(catch erlang:list_to_integer(Value,Base))
- end,[{" 1",1},{" 1",37},{"2",2},{"C",11},
+ end,[{" 1",1},{" 1",37},{"2",2},{"B",11},{"b",11},{":", 16},
{"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111z",16},
{"1z111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",16},
{"111z11111111",16}]),