Skip to content

Commit

Permalink
Fix Bugzilla 24685 - std.stdio.File.rawRead allows reading raw pointe…
Browse files Browse the repository at this point in the history
…rs from files in @safe code
  • Loading branch information
ntrel committed Jul 26, 2024
1 parent c00a5ee commit f01a213
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,9 @@ Throws: `ErrnoException` if the file is not opened or the call to `fread` fails.
assert(buf == "\r\n\n\r\n");
}

// https://issues.dlang.org/show_bug.cgi?id=24685
static assert(!__traits(compiles, (File f) @safe { int*[1] bar; f.rawRead(bar[]); }));

// https://issues.dlang.org/show_bug.cgi?id=21729
@system unittest
{
Expand Down Expand Up @@ -4534,6 +4537,13 @@ private auto trustedFwrite(T)(FILE* f, const T[] obj) @trusted
* Convenience function that forwards to `core.stdc.stdio.fread`
*/
private auto trustedFread(T)(FILE* f, T[] obj) @trusted
if (!imported!"std.traits".hasIndirections!T)
{
return fread(obj.ptr, T.sizeof, obj.length, f);
}

private auto trustedFread(T)(FILE* f, T[] obj) @system
if (imported!"std.traits".hasIndirections!T)
{
return fread(obj.ptr, T.sizeof, obj.length, f);
}
Expand Down

0 comments on commit f01a213

Please sign in to comment.