[Issue 16385] New: std.range: undefined behaviour when skipping over 0xff in string.popFront
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Sun Aug 14 02:30:06 PDT 2016
    
    
  
https://issues.dlang.org/show_bug.cgi?id=16385
          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 at puremagic.com
          Reporter: r.sagitario at 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.
--
    
    
More information about the Digitalmars-d-bugs
mailing list