Skip to content

Commit

Permalink
Merge pull request #4671 from WalterBright/utf-trusted
Browse files Browse the repository at this point in the history
std.utf: fix unsafe .ptr usage
  • Loading branch information
9il authored Jul 28, 2016
2 parents ca1d015 + e4f5ce7 commit 77bee52
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions std/utf.d
Original file line number Diff line number Diff line change
Expand Up @@ -2752,7 +2752,7 @@ private P toUTFzImpl(P, S)(S str) @safe pure
// unreadable. Otherwise, it's definitely pointing to valid
// memory.
if ((cast(size_t)p & 3) && *p == '\0')
return str.ptr;
return &str[0];
}

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

if ((cast(size_t)p & 3) && *p == '\0')
return str.ptr;
return &str[0];
}

str ~= '\0';
return str.ptr;
return &str[0];
}
//const(C)[] -> C* or immutable(C)* or
//C[] -> immutable(C)*
Expand Down Expand Up @@ -2811,7 +2811,7 @@ private P toUTFzImpl(P, S)(S str) @safe pure
retval.put(c);
retval.put('\0');

return cast(P)retval.data.ptr;
return () @trusted { return cast(P)retval.data.ptr; } ();
}

@safe pure unittest
Expand Down

0 comments on commit 77bee52

Please sign in to comment.