Skip to content

Commit

Permalink
Merge pull request #8517 from vali0901/issue_13893
Browse files Browse the repository at this point in the history
Fix Issue 13893 - rawRead must take a non-empty buffer
  • Loading branch information
RazvanN7 authored Jul 24, 2022
2 parents e38674b + 1d16213 commit f3b703e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -1132,10 +1132,9 @@ each item is inferred from the size and type of the input array, respectively.
Returns: The slice of `buffer` containing the data that was actually read.
This will be shorter than `buffer` if EOF was reached before the buffer
could be filled.
could be filled. If the buffer is empty, it will be returned.
Throws: `Exception` if `buffer` is empty.
`ErrnoException` if the file is not opened or the call to `fread` fails.
Throws: `ErrnoException` if the file is not opened or the call to `fread` fails.
`rawRead` always reads in binary mode on Windows.
*/
Expand All @@ -1144,7 +1143,7 @@ Throws: `Exception` if `buffer` is empty.
import std.exception : enforce, errnoEnforce;

if (!buffer.length)
throw new Exception("rawRead must take a non-empty buffer");
return buffer;
enforce(isOpen, "Attempting to read from an unopened file");
version (Windows)
{
Expand Down Expand Up @@ -1211,6 +1210,16 @@ Throws: `Exception` if `buffer` is empty.
}
}

// https://issues.dlang.org/show_bug.cgi?id=13893
@system unittest
{
import std.exception : assertNotThrown;

File f;
ubyte[0] u;
assertNotThrown(f.rawRead(u));
}

/**
Calls $(HTTP cplusplus.com/reference/clibrary/cstdio/fwrite.html, fwrite) for the file
handle. The number of items to write and the size of each
Expand Down

0 comments on commit f3b703e

Please sign in to comment.