Skip to content

Commit

Permalink
Merge branch 'sverk/large-list_to_integer-bug/OTP-12624' into maint
Browse files Browse the repository at this point in the history
* sverk/large-list_to_integer-bug/OTP-12624:
  erts: Fix bug in list_to_integer for very large strings
  • Loading branch information
sverker committed Mar 27, 2015
2 parents d477e59 + 59ec304 commit cbceea6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions erts/emulator/beam/bif.c
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ static int do_list_to_integer(Process *p, Eterm orig_list,
Uint ui = 0;
int skip = 0;
int neg = 0;
int n = 0;
Sint n = 0;
int m;
int lg2;
Eterm res;
Expand Down Expand Up @@ -2855,7 +2855,9 @@ static int do_list_to_integer(Process *p, Eterm orig_list,
else i = (Sint)ui;
res = make_small(i);
} else {
lg2 = (n+1)*230/69+1;
/* Convert from log10 to log2 by multiplying with 1/log10(2)=3.3219
which we round up to (3 + 1/3) */
lg2 = (n+1)*3 + (n+1)/3 + 1;
m = (lg2+D_EXP-1)/D_EXP; /* number of digits */
m = BIG_NEED_SIZE(m); /* number of words + thing */

Expand Down
6 changes: 5 additions & 1 deletion erts/emulator/test/num_bif_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,11 @@ t_string_to_integer(Config) when is_list(Config) ->
{"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111z",16},
{"1z111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",16},
{"111z11111111",16}]),


%% log2 calculation overflow bug in do_integer_to_list (OTP-12624)
%% Would crash with segv
0 = list_to_integer(lists:duplicate(10000000,$0)),

ok.

test_sti(Num) ->
Expand Down

0 comments on commit cbceea6

Please sign in to comment.