[erlang-bugs] bug in erl_interface

Björn-Egil Dahlberg egil@REDACTED
Mon Dec 16 17:39:16 CET 2013


I don't stuff will break from this, so I wouldn't consider it a bug per se.

For instance,
7> erlang:term_to_binary(1 bsl 29).
<<131,98,32,0,0,0>>

ok, but you could also define 1 bsl 29 = 536870912 as,
<<131,110,4,0,0,0,0,32>> (SMALL_BIG)
in the external format, so

9> erlang:binary_to_term(<<131,110,4,0,0,0,0,32>>).
536870912

The "proper" way to encode should probably be as you describe though but 
I think it correct external format encoded from ei .. erl_interface 
legacy, what a bundle of joy =)

// Björn-Egil

On 2013-12-16 16:25, Serge Aleynikov wrote:
> I believe there's a bug in the definition of ERL_MIN, ERL_MAX:
>
> *grep -n -A1 ERL_MAX lib/erl_interface*/src/legacy/erl_eterm.h
> 28:#define ERL_MAX_COUNT     0xffffff
> 29:#define ERL_MAX ((1 << 27)-1)
> 30-#define ERL_MIN -(1 << 27)
>
> The macros are used by lib/erl_interface/src/encode/encode_longlong.c:
>
> *grep -n -B3 -A5 ERL_MAX lib/erl_interface/src/encode/encode_longlong.c *
> 63-         put8(s,ERL_SMALL_INTEGER_EXT);
> 64-         put8(s,(p & 0xff));
> 65-     }
> 66:    } else if ((p <= ERL_MAX) && (p >= ERL_MIN)) {
> 67-     /* FIXME: Non optimal, could use (p <= LONG_MAX) && (p >= 
> LONG_MIN)
> 68-        and skip next case */
> 69-     if (!buf) s += 5;
> 70-     else {
> 71-         put8(s,ERL_INTEGER_EXT);
>
> It seems to me that these definitions are obsolete as the VM encodes 
> integers up to (1 << 31)-1 as ERL_INTEGER_EXT (98), and only above 
> that as ERL_SMALL_BIG (110):
>
> 1> term_to_binary(1 bsl 31 - 1).
> <<131,98,127,255,255,255>>
> 2> term_to_binary(1 bsl 31).
> <<131,110,4,0,0,0,0,128>>
>
> So the proper defines should be:
>
> *lib/erl_interface*/src/legacy/erl_eterm.h:29:
> #define ERL_MAX ((1 << *_31_*)-1)
> #define ERL_MIN -(1 << *_31_*)
>
> Serge
>
>
>
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20131216/88e5a436/attachment.htm>


More information about the erlang-bugs mailing list