Possible bug in skipOver() from std/algorithm/searching.d
Danny Arends via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jan 22 01:55:49 PST 2017
Hey all,
I encountered some unexpected behavior in std.format, I was
parsing Wavefront obj file, and ran into an issue. I updated the
compiler to the latest stable version (// DMD64 D Compiler
v2.072.2), however I think it's a Phobos related issue.
Given the following code:
---- test.d ----
import std.stdio, std.algorithm, std.conv, std.format, std.string;
void main() {
int x;
for (auto t = 40; t < 50; t++) {
// Create a string holding a number and put a forward slash
behind it
string l = to!string(t) ~ "/";
// Write the created string to the ouput
writef("'%s'", l);
// Read the number using the formattedRead function
formattedRead(l, "%d", &x);
// Write the number to the ouput
writef(" -> '%d'", x);
// Skip over the loaded number
l.skipOver(x);
// Print what is left of the string
writeln(" -> '", l, "'");
}
}
-------------------
After running this code dmd -run test.d
I get the following output:
'40/' -> '40' -> '/'
'41/' -> '41' -> '/'
'42/' -> '42' -> '/'
'43/' -> '43' -> '/'
'44/' -> '44' -> '/'
'45/' -> '45' -> '/'
'46/' -> '46' -> '/'
'47/' -> '47' -> ''
'48/' -> '48' -> '/'
'49/' -> '49' -> '/'
Why is in the case of 47, the slash at the end eaten up by the
skipOver function ?
I tested all numbers from 0 to 1000, and it only occurs when the
number is 47 (?!)
Can anyone confirm this, since it looks like such a weird bug to
me ?
Kind regards,
Danny Arends
More information about the Digitalmars-d
mailing list