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

Edwin Fine erlang-questions_efine@REDACTED
Tue Aug 26 08:46:21 CEST 2008


Bjorn,

Thank you for updating the documentation.

However, I strongly disagree that silently truncating integers in conversion
to binaries is a feature. The huge number of bugs in C/C++ programming due
to overflows in general, and the creation of secure integer libraries to
prevent this, should be a strong indicator of the potential harm in allowing
this.

In "Programming Erlang", Joe Armstrong writes:

"Erlang uses arbitrary-sized integers for performing integer arithmetic. In
Erlang, integer arithmetic is exact, so you don't have to worry about
arithmetic overflows or not being able to represent an integer in a cer-
tain word size."

But as soon as you convert to binary, that protection is lost and you
*do*have to worry about integer overflows. Erlang is designed for
programming
fault-tolerant systems, yet this "feature" actually contributes to potential
faults. The compiler and run-time should be there to help us, not hinder us.

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?

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

> 2008/8/22 Edwin Fine <erlang-questions_efine@REDACTED>
>
>> I refer to the following post. I was caught unawares by this apparently
>> undocumented behavior.
>>
>> http://www.erlang.org/pipermail/erlang-questions/2007-July/027657.html
>>
>> May I strongly recommend placing this information (taken from the above
>> post) in the Erlang Reference Manual, in the section on binaries. It may
>> save other people time and confusion. A further question is whether or not
>> this *should* be the behavior. As a language used for writing highly
>> reliable systems, shouldn't this overflow condition be caught? Maybe as an
>> optional run-time flag?
>>
>>
> We consider the behavior to be a feature.
>
> I have now added some information about the behavior to the reference
> manual (to appear in R12B-4).
>
> /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-bugs/attachments/20080826/8a864ea5/attachment.htm>


More information about the erlang-bugs mailing list