Skip to content

Commit 0cf6acc

Browse files
nyhwkozaczuk
authored andcommitted
Add test for fread() hang when reading from a directory
In commit 0d4d8fd we fixed a bug where fread() on a directory hangs, instead of resulting in an error as expected. However, we didn't have a test for this case - and this patch adds one. The new test hangs before the aforementioned commit, and passes without it. The test also passes on Linux. Signed-off-by: Nadav Har'El <[email protected]> Message-Id: <[email protected]>
1 parent bba6668 commit 0cf6acc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/tst-fread.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ int main()
6969
fclose(fp);
7070
}
7171

72+
// Test that if read from a directory with fread(), we get an error,
73+
// not an endless loop as we did before commit
74+
// 0d4d8fd6752521bed92a4be194403b89955b591f.
75+
std::cerr << "opening /\n";
76+
fp = fopen("/", "r");
77+
expect(!fp, false);
78+
if (fp) {
79+
char buf[4096];
80+
expect(fread(buf, 1, 4096, fp), (size_t)0);
81+
expect(ferror(fp), 1);
82+
expect(feof(fp), 0);
83+
fclose(fp);
84+
}
85+
7286
std::cout << "SUMMARY: " << tests << " tests, " << fails << " failures\n";
7387
return fails == 0 ? 0 : 1;
7488

0 commit comments

Comments
 (0)