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
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/0d213a9288a672721da442c331df955188c5ddb7 Fix issue 16385: do not pass 0 to bsr, it has undefined return value https://github.com/dlang/phobos/commit/d753c8e3773f15647508fd8c30cad964982d2f37 Merge pull request #4729 from rainers/issue16385 Fix issue 16385: std.range: undefined behaviour when skipping over 0xff in string.popFront
Comment #2 by github-bugzilla — 2016-10-01T11:46:38Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/0d213a9288a672721da442c331df955188c5ddb7 Fix issue 16385: do not pass 0 to bsr, it has undefined return value https://github.com/dlang/phobos/commit/d753c8e3773f15647508fd8c30cad964982d2f37 Merge pull request #4729 from rainers/issue16385