www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16385] New: std.range: undefined behaviour when skipping over


          Issue ID: 16385
           Summary: std.range: undefined behaviour when skipping over 0xff
                    in string.popFront
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

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.

Aug 14 2016