[Issue 3805] New: std.format writeUpToFormatSpec function has subtle loop index bug, will drop character after a %%
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 15 20:32:03 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3805
Summary: std.format writeUpToFormatSpec function has subtle
loop index bug, will drop character after a %%
Product: D
Version: 2.040
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: y0uf00bar at gmail.com
--- Comment #0 from Michael Rynn <y0uf00bar at gmail.com> 2010-02-15 20:32:00 PST ---
private void writeUpToFormatSpec(OutRange, S)(ref OutRange w, ref S fmt)
{
for (size_t i = 0; i < fmt.length; ++i)
{
if (fmt[i] != '%') continue;
if (fmt[++i] != '%')
{
// spec found, print and bailout
w.put(fmt[0 .. i - 1]);
fmt = fmt[i .. $];
return;
}
// doubled! Now print whatever we had, then update the string
// and move on
w.put(fmt[0 .. i]);
fmt = fmt[i + 1 .. $];
/// BUG !! unable to ever reset a size_t for loop index value to zero, because
it is always incremented to 1 at start of next iteration. This means next
character after a '%%' will be dropped.
i = 0;
}
/// A better version might look like this.
/// Take the i++ out of the for loop top, move it to the first test case.
for (size_t i = 0; i < fmt.length;)
{
if (fmt[i++] != '%') continue;
if (fmt[i] != '%')
{
// spec found, print and bailout
w.put(fmt[0 .. i - 1]);
fmt = fmt[i .. $];
return;
}
// doubled! Now print whatever we had, then update the string
// and move on
w.put(fmt[0 .. i]);
fmt = fmt[i + 1 .. $];
i = 0; // OK now, will be 0 at the top of the loop
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list