[erlang-questions] Integer truncation in binary conversion considered harmful

Edwin Fine erlang-questions_efine@REDACTED
Tue Aug 26 09:54:15 CEST 2008


That would work, too, although it could be considered that libraries that
depend on the truncation behavior may in fact unwittingly be harboring
truncation bugs, and might be better served by explicitly truncating the
integer down to size prior to converting to binary. Perhaps a
truncate(Integer, NumBytes) BIF could be provided. Still, being able to turn
on range checking for a specific binary conversion (-pragma(range-check),
anyone?) or a module might be a very nice compromise feature.

I'll look into what it takes to write an EEP and submit one if I think I can
get it right ;-)


On Tue, Aug 26, 2008 at 3:24 AM, Bjorn Gustavsson <bgustavsson@REDACTED>wrote:

> On Tue, Aug 26, 2008 at 8:46 AM, Edwin Fine <
> erlang-questions_efine@REDACTED> wrote:
>> How difficult could it be to add *optional* run-time checking to detect
>> this condition without a serious risk of adverse effects on the correctness
>> of Erlang run-time execution?
> If checking is turned on for the entire run-time system, library code that
> depends on the truncation could fail.
> I think it would be better to add optional support in the compiler to turn
> on checks (either for an entire module, or for individual segments of
> a binary).
> If someone writes an EEP, we will consider implementing it.
> /Bjorn
> --
> Björn Gustavsson, Erlang/OTP, Ericsson AB

For every expert there is an equal and opposite expert - Arthur C. Clarke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080826/62876d62/attachment.htm>

More information about the erlang-questions mailing list