Skip to content

Commit ebafa4e

Browse files
authored
Fix bugzilla 24832 - Segfault in hex string (dlang/dmd!17024)
* Fix bugzilla 24832 - Segfault in hex string * Fix lack of camelcasing on stable branch
1 parent 24b56d8 commit ebafa4e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

dmd/dcast.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
23362336
Type tb = t.toBasetype();
23372337
Type typeb = e.type.toBasetype();
23382338

2339-
if (e.hexString && !e.committed)
2339+
if (e.hexString && !e.committed && tb.nextOf().isintegral)
23402340
{
23412341
const szx = cast(ubyte) tb.nextOf().size();
23422342
if (szx != se.sz && (e.len % szx) == 0)

dmd/dinterpret.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6107,7 +6107,7 @@ public:
61076107
{
61086108
auto se = e1.isStringExp();
61096109
// Allow casting a hex string literal to short[], int[] or long[]
6110-
if (se && se.hexString && se.postfix == StringExp.NoPostfix)
6110+
if (se && se.hexString && se.postfix == StringExp.NoPostfix && e.to.nextOf().isintegral)
61116111
{
61126112
const sz = cast(size_t) e.to.nextOf().size;
61136113
if ((se.len % sz) != 0)

tests/dmd/fail_compilation/hexstring.d

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ fail_compilation/hexstring.d(39): perhaps remove postfix `c` from hex str
1414
fail_compilation/hexstring.d(40): Error: hex string with `dstring` type needs to be multiple of 4 bytes, not 5
1515
fail_compilation/hexstring.d(41): Error: cannot implicitly convert expression `x"11223344"d` of type `dstring` to `immutable(float[])`
1616
fail_compilation/hexstring.d(42): Error: cannot implicitly convert expression `x"1122"w` of type `wstring` to `immutable(ubyte[])`
17+
fail_compilation/hexstring.d(50): Error: array cast from `string` to `S[]` is not supported at compile time
1718
fail_compilation/hexstring.d(28): Error: cannot implicitly convert expression `x"123F"` of type `string` to `ubyte[]`
1819
---
1920
*/
2021
immutable ubyte[] s0 = x"123F";
2122
static assert(s0[0] == 0x12);
2223
static assert(s0[1] == 0x3F);
2324
immutable byte[] s1 = x"123F";
24-
2525
enum E(X) = cast(X[]) x"AABBCCDD";
2626
static assert(E!int[0] == 0xAABBCCDD);
2727

@@ -40,3 +40,11 @@ immutable uint[] f11 = cast(immutable uint[]) x"AABBCCDD"c;
4040
immutable uint[] f12 = x"1122334455"d;
4141
immutable float[] f13 = x"11223344"d;
4242
immutable ubyte[] f14 = x"1122"w;
43+
44+
// https://issues.dlang.org/show_bug.cgi?id=24832
45+
struct S
46+
{
47+
ushort l0, l1, l2, l3, l4, l5;
48+
}
49+
50+
immutable S[] returnValues = cast(S[]) x"FFFFFFFFFFFFFFFFFFFFFFFF";

0 commit comments

Comments
 (0)