Bug 16385 – std.range: undefined behaviour when skipping over 0xff in string.popFront
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2016-08-14T09:30:00Z
Last change time
2016-10-01T11:46:38Z
Assigned to
nobody
Creator
r.sagitario
Comments
Comment #0 by r.sagitario — 2016-08-14T09:30:06Z
This unittest in std.exception:
pure @safe unittest
{
import std.algorithm : equal;
import std.range : retro;
import std.utf : UTFException;
auto str = "hello\xFFworld"; // 0xFF is an invalid UTF-8 code unit
auto handled = str.handle!(UTFException, RangePrimitive.access,
(e, r) => ' '); // Replace invalid code points with spaces
assert(handled.equal("hello world")); // `front` is handled,
}
fails for me depending on compilation options and platform.
This happens because string.popFront uses the intrinsic bsr, but doesn't check the undefined case when the argument is 0.
Comment #1 by github-bugzilla — 2016-08-14T11:27:07Z