[m-rev.] for review: fix a bug in the string to int and uint overflow checks

Zoltan Somogyi zoltan.somogyi at runbox.com
Sat Jul 18 06:37:43 AEST 2026



On Fri, 17 Jul 2026 23:23:53 +1000, Julien Fischer <jfischer at opturion.com> wrote:
> Looking at how such overflow checking is implemented in strtol,
> there's a better approach
> we can probably use that hoists the division out of the loop and only
> performs comparisons
> within the loop. (It should avoid the need for a switch entirely.).

I look forward to seeing it.
 
> > I would rename this to either accumulate_positive_int
> > or accumulate_non_negative_int.
> 
> Renamed to the former, which is more consistent with the surrounding predicates.

What I meant was that it should depend on whether zero is
an allowed input or not.

> Java provides both, C and C# provide only truncating division.
> The Mercury standard library implements flooring division (div)
> in Mercury for all of our signed integer types. We only require
> that the target languages provide truncating division.
> 
> > If you know, it would help to mention them here.
> 
> How is what the target languages provide relevant here?

Having the target language implement natively the kind of division
we want to use can reduce overheads, but you are right, this is probably
not that significant.

Zoltan.


More information about the reviews mailing list