[Issue 15586] std.utf.toUTF8() segfaults when fed an invalid dchar
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Wed Jan 20 15:07:49 PST 2016
    
    
  
https://issues.dlang.org/show_bug.cgi?id=15586
--- Comment #5 from thomas.bockman at gmail.com ---
> Keep in mind, though, that one *could* argue that casting an arbitrary value
> to dchar already constitutes UB
This has already been settled. It's not:
    http://forum.dlang.org/post/oionrfexehapzicgpbrw@forum.dlang.org
> Generally, you probably shouldn't be casting stuff unless you know what
> you're doing and are ready to handle the consequences when things go wrong.
1) No casting is required to trigger this bug. I was just giving you a
simplified test case. Here's a slightly less simple one, without any casts:
import std.stdio;
void main() {
    import std.utf : toUTF8;
    dchar a = dchar.max;
    a += 1;
    char[4] buf = void;
    auto b = toUTF8(buf, a);
    import std.stdio;
    writeln(b);
}
2) "If you don't want segfaults, don't cast stuff" is an awful solution to a
hard crash in @safe code. There is no good reason that casts of basic numeric
or character types should cause this kind of failure.
--
    
    
More information about the Digitalmars-d-bugs
mailing list