[rust-dev] Integer overflow, round -2147483648

Daniel Micay danielmicay at gmail.com
Sun Jun 22 21:15:20 PDT 2014


On 22/06/14 06:43 PM, Clark Gaebel wrote:
> I think a reasonable middle ground is to have checked operators that
> look a little funny. Kind of like swift, but in reverse:
> 
>> malloc((number_of_elements +~ 12) *~ size_of::<int>())
> 
> Where adding a ~ to the end of an operator makes it check for overflow.
> This would certainly look nicer than stuff like:
> 
>> malloc(number_of_elements.checked_add(12).checked_mul(size_of::<int>()))
> 
> lying around in low level data structures code.
> 
> It also keeps the default fast, which is very important.
> 
>   - Clark

Along with an opt-in lint to warn about usage of the unchecked
operators, I think that's the way to go. Since it would be backwards
compatible, it doesn't need to be done before 1.0.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140623/a7c90c25/attachment.sig>


More information about the Rust-dev mailing list