[Issue 15586] std.utf.toUTF8() segfaults when fed an invalid dchar

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jan 20 14:38:53 PST 2016


https://issues.dlang.org/show_bug.cgi?id=15586

--- Comment #4 from hsteoh at quickfur.ath.cx ---
Keep in mind, though, that one *could* argue that casting an arbitrary value to
dchar already constitutes UB, if dchars are deemed to only contain valid
Unicode codepoints. If you need to work with incoming character data of unknown
validity, you're probably better off working with uint (or uint[], ubyte[],
etc.) instead, and only convert to dchar (string, etc.) after explicit
validation.

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.

--


More information about the Digitalmars-d-bugs mailing list