[erlang-bugs] bug in erl_interface

Serge Aleynikov serge@REDACTED
Mon Dec 16 16:25:42 CET 2013


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


More information about the erlang-bugs mailing list