Skip to content

Commit 77bee52

Browse files
authored
Merge pull request #4671 from WalterBright/utf-trusted
std.utf: fix unsafe .ptr usage
2 parents ca1d015 + e4f5ce7 commit 77bee52

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

std/utf.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,7 @@ private P toUTFzImpl(P, S)(S str) @safe pure
27522752
// unreadable. Otherwise, it's definitely pointing to valid
27532753
// memory.
27542754
if ((cast(size_t)p & 3) && *p == '\0')
2755-
return str.ptr;
2755+
return &str[0];
27562756
}
27572757

27582758
return toUTFzImpl!(P, const(C)[])(cast(const(C)[])str);
@@ -2779,11 +2779,11 @@ private P toUTFzImpl(P, S)(S str) @safe pure
27792779
auto p = trustedPtrAdd(str);
27802780

27812781
if ((cast(size_t)p & 3) && *p == '\0')
2782-
return str.ptr;
2782+
return &str[0];
27832783
}
27842784

27852785
str ~= '\0';
2786-
return str.ptr;
2786+
return &str[0];
27872787
}
27882788
//const(C)[] -> C* or immutable(C)* or
27892789
//C[] -> immutable(C)*
@@ -2811,7 +2811,7 @@ private P toUTFzImpl(P, S)(S str) @safe pure
28112811
retval.put(c);
28122812
retval.put('\0');
28132813

2814-
return cast(P)retval.data.ptr;
2814+
return () @trusted { return cast(P)retval.data.ptr; } ();
28152815
}
28162816

28172817
@safe pure unittest

0 commit comments

Comments
 (0)