Bug 9126 – parse!int fails on size_t.max+1 digits long input (overflow)
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-08T23:40:00Z
Last change time
2015-06-09T05:11:41Z
Keywords
pull
Assigned to
nobody
Creator
nilsbossung
Comments
Comment #0 by nilsbossung — 2012-12-08T23:40:03Z
std.conv.parse!int uses a counter just to see if anything could be parsed.
When the counter overflows, the state jumps back to "at start", which is wrong, of course.
Test case (takes some minutes):
---
import std.conv: parse;
import std.range: chain, repeat;
void main() {
auto seven = chain(repeat(cast(dchar) '0', size_t.max), "7");
assert(parse!int(seven) == 7);
auto eleven = chain(repeat(cast(dchar) '0', size_t.max), "B");
assert(parse!int(eleven, 13) == 11);
}
---
Pull request follows.