summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Gustavsson <bjorn@erlang.org>2023-05-03 13:12:56 +0200
committerBjörn Gustavsson <bjorn@erlang.org>2023-05-03 13:34:06 +0200
commite718e07d578af2ca9726641751101e45b80cd25b (patch)
tree001c917311a8c2e6015bca1bc8da1056d755d767
parent465720cf8b6f3c14ebca43c3ce852d135b86bdbe (diff)
downloaderlang-e718e07d578af2ca9726641751101e45b80cd25b.tar.gz
Eliminate crash in beam_types
Closes #7198
-rw-r--r--lib/compiler/src/beam_types.erl24
-rw-r--r--lib/compiler/test/beam_type_SUITE.erl7
2 files changed, 17 insertions, 14 deletions
diff --git a/lib/compiler/src/beam_types.erl b/lib/compiler/src/beam_types.erl
index b668251f79..c3bf7c8fae 100644
--- a/lib/compiler/src/beam_types.erl
+++ b/lib/compiler/src/beam_types.erl
@@ -1179,14 +1179,13 @@ float_from_range(none) ->
none;
float_from_range(any) ->
#t_float{};
-float_from_range({'-inf','+inf'}) ->
- #t_float{};
-float_from_range({'-inf',Max}) ->
- make_float_range('-inf', safe_float(Max));
-float_from_range({Min,'+inf'}) ->
- make_float_range(safe_float(Min), '+inf');
-float_from_range({Min,Max}) ->
- make_float_range(safe_float(Min), safe_float(Max)).
+float_from_range({Min0,Max0}) ->
+ case {safe_float(Min0),safe_float(Max0)} of
+ {'-inf','+inf'} ->
+ #t_float{};
+ {Min,Max} ->
+ #t_float{elements={Min,Max}}
+ end.
safe_float(N) when is_number(N) ->
try
@@ -1194,12 +1193,9 @@ safe_float(N) when is_number(N) ->
catch
error:_ when N < 0 -> '-inf';
error:_ when N > 0 -> '+inf'
- end.
-
-make_float_range('-inf', '+inf') ->
- #t_float{};
-make_float_range(Min, Max) ->
- #t_float{elements={Min, Max}}.
+ end;
+safe_float('-inf'=NegInf) -> NegInf;
+safe_float('+inf'=PosInf) -> PosInf.
integer_from_range(none) ->
none;
diff --git a/lib/compiler/test/beam_type_SUITE.erl b/lib/compiler/test/beam_type_SUITE.erl
index 18a29f2643..21bfe5c7ec 100644
--- a/lib/compiler/test/beam_type_SUITE.erl
+++ b/lib/compiler/test/beam_type_SUITE.erl
@@ -782,6 +782,8 @@ float_overflow(_Config) ->
Res2 = id((-1 bsl 1023) * two()),
Res2 = float_overflow_2(),
+ {'EXIT',{{bad_filter,[0]},_}} = catch float_overflow_3(),
+
ok.
%% GH-7178: There would be an overflow when converting a number range
@@ -808,6 +810,11 @@ float_overflow_2() ->
two() -> 2.
+float_overflow_3() ->
+ [0 || <<>> <= <<>>,
+ [0 || (floor(1.7976931348623157e308) bsl 1) >= (1.0 + map_size(#{}))]
+ ].
+
arity_checks(_Config) ->
%% ERL-549: an unsafe optimization removed a test_arity instruction,
%% causing the following to return 'broken' instead of 'ok'.