Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions std/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -2341,15 +2341,17 @@ in
body
{
import core.checkedint : mulu, addu;
import std.exception : enforce;

if (radix == 10)
return parse!Target(s);

immutable uint beyond = (radix < 10 ? '0' : 'a'-10) + radix;
enforce!ConvException(!s.empty, "s must not be empty in integral parse");

immutable uint beyond = (radix < 10 ? '0' : 'a'-10) + radix;
Target v = 0;
bool atStart = true;

for (; !s.empty; s.popFront())
do
{
uint c = s.front;
if (c < '0')
Expand All @@ -2372,20 +2374,12 @@ body

bool overflow = false;
auto nextv = v.mulu(radix, overflow).addu(c - '0', overflow);
if (overflow || nextv > Target.max)
goto Loverflow;
enforce!ConvOverflowException(!overflow && nextv < Target.max, "Overflow in integral conversion");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should have been <=?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v = cast(Target) nextv;
s.popFront();
} while (!s.empty);

atStart = false;
}
if (atStart)
goto Lerr;
return v;

Loverflow:
throw new ConvOverflowException("Overflow in integral conversion");
Lerr:
throw convError!(Source, Target)(s, radix);
}

@safe pure unittest
Expand Down