[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:23:05 CEST 2013


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/4aab25a3/attachment.htm>


More information about the erlang-patches mailing list