[Issue 24337] New: Segfault when printing an int[] cast from a string literal
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jan 12 12:12:01 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24337
Issue ID: 24337
Summary: Segfault when printing an int[] cast from a string
literal
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: ice-on-valid-code
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dkorpel at live.nl
This code segfaults dmd:
```D
immutable ushort[] z = cast(immutable ushort[]) "ab"w;
pragma(msg, z);
```
The problem is in expressionsem.d:
```
StringExp toUTF8(StringExp se, Scope* sc)
{
if (se.sz != 1)
{
// Convert to UTF-8 string
se.committed = false;
Expression e = castTo(se, sc, Type.tchar.arrayOf());
e = e.optimize(WANTvalue);
auto result = e.isStringExp();
assert(result.sz == 1);
return result;
}
return se;
}
```
This function assumes casting a StringExp to char[] will always succeed, which
is false in the above case.
--
More information about the Digitalmars-d-bugs
mailing list