D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14370 - std.utf.toUTF8 has an incorrect contract
Summary: std.utf.toUTF8 has an incorrect contract
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-29 02:09 UTC by erikas.aubade
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description erikas.aubade 2015-03-29 02:09:22 UTC
The following code seems to cause, depending on system and implementation, either a segfault, sigabrt, or "HLT instruction" exception.

import std.stdio;
import std.encoding;

void main() {
   writeln(INVALID_SEQUENCE);
}
Comment 1 briancschott 2015-03-29 02:11:43 UTC
There is a contract in toUTF8 that checks the return value of isValidDchar, but isValidDchar will return true for some code points that toUTF8 does not handle.
Comment 2 basile-z 2017-09-14 16:48:11 UTC
It throws an UTF exception nowadays and BTW toUTF8 is not used anymore since it's deprecated in favor of encode().