Skip to content

Commit

Permalink
Add test for fread() hang when reading from a directory
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nyh authored and wkozaczuk committed Dec 29, 2020
1 parent bba6668 commit 0cf6acc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/tst-fread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ int main()
fclose(fp);
}

// Test that if read from a directory with fread(), we get an error,
// not an endless loop as we did before commit
// 0d4d8fd6752521bed92a4be194403b89955b591f.
std::cerr << "opening /\n";
fp = fopen("/", "r");
expect(!fp, false);
if (fp) {
char buf[4096];
expect(fread(buf, 1, 4096, fp), (size_t)0);
expect(ferror(fp), 1);
expect(feof(fp), 0);
fclose(fp);
}

std::cout << "SUMMARY: " << tests << " tests, " << fails << " failures\n";
return fails == 0 ? 0 : 1;

Expand Down

0 comments on commit 0cf6acc

Please sign in to comment.