[erlang-patches] integer_to_binary/2 returns incorrect values or crashes with bases other than 10

Juan Jose Comellas juanjo@REDACTED
Mon Sep 9 19:38:12 CEST 2013


Sorry, there was a mistake in the commit message for the fix I had
previously sent. I've canceled the original pull request and created a new
one. The correct branch is in:

git fetch git://github.com/jcomellas/otp.git jc-integer-to-binary2_1

https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer-to-binary2_1
https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer-to-binary2_1.patch


On Mon, Sep 9, 2013 at 2:23 PM, Juan Jose Comellas <juanjo@REDACTED>wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20130909/a736b252/attachment.htm>


More information about the erlang-patches mailing list