integer_to_binary/2 returns incorrect values or crashes with bases other than 10

Juan Jose Comellas <[email protected]>
Newsgroups gmane.comp.lang.erlang.patches
Message-ID <CAOLqyqydAeminLahnDh=wcKGJyJEGf8xLigWS+EvoZmByt2mnQ@mail.gmail.com>
The integer_to_binary/2 function works perfectly with base 10 (because it
just calls integer_to_binary/1), but when used with other bases it fails
when 0 or a negative number are passed as the number to convert. e.g.:

1> integer_to_binary(0, 16).
<<>>

2> integer_to_binary(-1, 16).
** exception error: bad argument
     in function  byte_size/1
        called as byte_size([])
     in call from erlang:integer_to_binary/3
     in call from integer_to_binary/2

The expected results are:

1> integer_to_binary(0, 16).
<<"0">>

2> integer_to_binary(-1, 16).
<<"-1">>

I've sent this change as a pull request, but on this branch there's the
patch to fix this problem and some tests to cover these cases.

git fetch git://github.com/jcomellas/otp.git jc-integer_to_binary2

https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer_to_binary2
https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer_to_binary2.patch

_______________________________________________
erlang-patches mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.