[erlang-bugs] io_list_to_binary returns wrong result for iolist of length 2^32

Erik Søe Sørensen ess@REDACTED
Wed Apr 13 17:17:01 CEST 2011



That would defeat the purpose of testing how iolist_to_binary handles large outputs though... :-)

----- Reply message -----
Fra: "Paul Davis" <paul.joseph.davis@REDACTED>
Dato: ons., apr. 13, 2011 16:28
Emne: [erlang-bugs] io_list_to_binary returns wrong result for iolist of length 2^32
Til: "Erik Søe Sørensen" <ess@REDACTED>
Cc: "erlang-bugs@REDACTED" <erlang-bugs@REDACTED>

On Wed, Apr 13, 2011 at 9:38 AM, Erik Søe Sørensen <ess@REDACTED> wrote:
> To reproduce:
>
>   $ erl
>   Erlang R14B (erts-5.8.1) [source] [64-bit] [smp:8:8] [rq:8]
>   [async-threads:0] [kernel-poll:false]
>
>   Eshell V5.8.1  (abort with ^G)
>   [snip]
>   6> iolist_to_binary(lists:foldl(fun(_,A) -> [A|A] end, [64],
>   lists:seq(1,32))).
>   <<>>
>   7>
>   size(v(-1)).
>       0
>   8> iolist_to_binary(lists:foldl(fun(_,A) -> [A|A] end, [64],
>   lists:seq(1,31))).
>   HUGE size (8589934632)
>   Aborted
>
>
> -- So, length 2^31 aborts the VM while 2^32 "simply" returns a wrong result.
>
> For size 2^31, I hypothesized that something went wrong when Eshell
> memorizes the result, but that does not appear to be the case:
>
>   erik@REDACTED:riak_kv-basho$ erl
>   Erlang R14B (erts-5.8.1) [source] [64-bit] [smp:8:8] [rq:8]
>   [async-threads:0] [kernel-poll:false]
>
>   Eshell V5.8.1  (abort with ^G)
>   1> iolist_to_binary(lists:foldl(fun(_,A) -> [A|A] end, [64],
>   lists:seq(1,31))), ok.
>   HUGE size (8589934632)
>   Aborted
>
> These tests were run on:
> $ uname -a
> Linux flitwick 2.6.31-22-generic #73-Ubuntu SMP Fri Feb 11 19:18:05 UTC 2011
> x86_64 GNU/Linux
>
>
> /Erik
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs
>

My guess is that this is that your lists are recursive. Try changing:

fun(_,A) -> [A|A] end

into:

fun(V,A) -> [V|A] end



More information about the erlang-bugs mailing list