Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

float_to_list/2 test fails with exception or segfault when digits range >= 9 #512

Open
@KronicDeth

Description

@KronicDeth

Failing

The following file fails to produce all output

init.erl

-module(init).
-export([start/0]).
-import(erlang, [append_element/2, display/1, float_to_list/2, make_tuple/2]).

start() ->
  lists().

lists() ->
   lists(0, 16).

lists(MaxDigits, MaxDigits) ->
  list(MaxDigits);
lists(Digits, MaxDigits) ->
  list(Digits),
  lists(Digits + 1, MaxDigits).

list(Digits) ->
  Decimals = pair(decimals, Digits),
  Options = [Decimals],
  display(float_to_list(12345.6789, Options)).

%% FIXME work around tuple lowering bug
pair(Key, Value) ->
  Empty = make_tuple(0, []),
  KeyTuple = append_element(Empty, Key),
  append_element(KeyTuple, Value).

Output

---- erlang::float_to_list_2::with_float::with_proper_list_options::with_decimals::without_compact::trailing_zeros_are_not_truncated stdout ----
thread 'erlang::float_to_list_2::with_float::with_proper_list_options::with_decimals::without_compact::trailing_zeros_are_not_truncated' panicked at 'assertion failed: `(left == right)`
  left: `"\"12346\"\n\"12345.7\"\n\"12345.68\"\n\"12345.679\"\n\"12345.6789\"\n\"12345.67890\"\n\"12345.678900\"\n\"12345.6789000\"\n\"12345.67890000\"\n\"12345.678900000\"\n\"12345.6789000000\"\nNoneValue { backtrace: <disabled> }\n"`,
 right: `"\"12346\"\n\"12345.7\"\n\"12345.68\"\n\"12345.679\"\n\"12345.6789\"\n\"12345.67890\"\n\"12345.678900\"\n\"12345.6789000\"\n\"12345.67890000\"\n\"12345.678900000\"\n\"12345.6789000000\"\n\"12345.67890000000\"\n\"12345.678900000001\"\n\"12345.6789000000008\"\n\"12345.67890000000079\"\n\"12345.678900000000795\"\n\"12345.6789000000007945\"\n"`: 
stdout = "12346"
"12345.7"
"12345.68"
"12345.679"
"12345.6789"
"12345.67890"
"12345.678900"
"12345.6789000"
"12345.67890000"
"12345.678900000"
"12345.6789000000"
NoneValue { backtrace: <disabled> }

stderr = thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NoneValue { backtrace: <disabled> }', liblumen_alloc/src/erts/term/convert.rs:365:1

Work-arounds

If the range of digits is changed from 0 to 16 to 0 to 10, no exception occurs. It also is not a problem

init.erl 0 to 10

-module(init).
-export([start/0]).
-import(erlang, [append_element/2, display/1, float_to_list/2, make_tuple/2]).

start() ->
  lists().

lists() ->
   lists(0, 10).

lists(MaxDigits, MaxDigits) ->
  list(MaxDigits);
lists(Digits, MaxDigits) ->
  list(Digits),
  lists(Digits + 1, MaxDigits).

list(Digits) ->
  Decimals = pair(decimals, Digits),
  Options = [Decimals],
  display(float_to_list(12345.6789, Options)).

%% FIXME work around tuple lowering bug
pair(Key, Value) ->
  Empty = make_tuple(0, []),
  KeyTuple = append_element(Empty, Key),
  append_element(KeyTuple, Value).

init.erl 11 to 16

-module(init).
-export([start/0]).
-import(erlang, [append_element/2, display/1, float_to_list/2, make_tuple/2]).

start() ->
  lists().

lists() ->
   lists(11, 16).

lists(MaxDigits, MaxDigits) ->
  list(MaxDigits);
lists(Digits, MaxDigits) ->
  list(Digits),
  lists(Digits + 1, MaxDigits).

list(Digits) ->
  Decimals = pair(decimals, Digits),
  Options = [Decimals],
  display(float_to_list(12345.6789, Options)).

%% FIXME work around tuple lowering bug
pair(Key, Value) ->
  Empty = make_tuple(0, []),
  KeyTuple = append_element(Empty, Key),
  append_element(KeyTuple, Value).

Segfault

The range 9..16 actually causes a segfault instead of the exception.

init.erl

-module(init).
-export([start/0]).
-import(erlang, [append_element/2, display/1, float_to_list/2, make_tuple/2]).

start() ->
  lists().

lists() ->
   lists(8, 16).

lists(MaxDigits, MaxDigits) ->
  list(MaxDigits);
lists(Digits, MaxDigits) ->
  list(Digits),
  lists(Digits + 1, MaxDigits).

list(Digits) ->
  Decimals = pair(decimals, Digits),
  Options = [Decimals],
  display(float_to_list(12345.6789, Options)).

%% FIXME work around tuple lowering bug
pair(Key, Value) ->
  Empty = make_tuple(0, []),
  KeyTuple = append_element(Empty, Key),
  append_element(KeyTuple, Value).

Output

---- erlang::float_to_list_2::with_float::with_proper_list_options::with_decimals::without_compact::trailing_zeros_are_not_truncated stdout ----
thread 'erlang::float_to_list_2::with_float::with_proper_list_options::with_decimals::without_compact::trailing_zeros_are_not_truncated' panicked at 'assertion failed: `(left == right)`
  left: `"\"12345.67890000\"\n\"12345.678900000\"\n\"12345.6789000000\"\n\"12345.67890000000\"\n\"12345.678900000001\"\n\"12345.6789000000008\"\n\"12345.67890000000079\"\n\"12345.678900000000795\"\n"`,
 right: `"\"12346\"\n\"12345.7\"\n\"12345.68\"\n\"12345.679\"\n\"12345.6789\"\n\"12345.67890\"\n\"12345.678900\"\n\"12345.6789000\"\n\"12345.67890000\"\n\"12345.678900000\"\n\"12345.6789000000\"\n\"12345.67890000000\"\n\"12345.678900000001\"\n\"12345.6789000000008\"\n\"12345.67890000000079\"\n\"12345.678900000000795\"\n\"12345.6789000000007945\"\n"`: 
stdout = "12345.67890000"
"12345.678900000"
"12345.6789000000"
"12345.67890000000"
"12345.678900000001"
"12345.6789000000008"
"12345.67890000000079"
"12345.678900000000795"

stderr = 
status_code = 
signal = segmentation fault (invalid address)', native_implemented/otp/tests/lib/erlang/float_to_list_2/with_float/with_proper_list_options/with_decimals/without_compact.rs:1:1

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompilerIssues pertaining to the compiler with no specific taghelp wantedWe'd love your help getting this one done!runtimeruntime/bifs

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions