The case for integer overflow checks?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Tue Sep 19 04:13:09 UTC 2017
On Monday, September 18, 2017 22:39:09 Moritz Maxeiner via Digitalmars-d
> On Monday, 18 September 2017 at 22:32:28 UTC, Dennis Cote wrote:
> > On Monday, 18 September 2017 at 13:25:55 UTC, Andrei
> > Alexandrescu wrote:
> >> For the record, with the help of std.experimental.checkedint,
> >> the change that fixes the code would be:
> >> malloc(width * height * 4) ==> malloc((checked(width) * height
> >> * 4).get)
> >> That aborts the application with a message if a multiplication
> >> overflows.
> > Can it do something other than abort? Can it throw an overflow
> > exception that could be caught to report the error and continue?
> Yes. Use one of the provided hooks (e.g. ) or write one
> that fits your use case.
>  https://dlang.org/phobos/std_experimental_checkedint.html#Warn
Yeah, it's really quite flexible with minimal code. Andrei talked about it
in his dconf 2017 talk:
- Jonathan M Davis
More information about the Digitalmars-d