Skip to content

Commit

Permalink
Throw MMapException if mmap fail.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Apr 3, 2024
1 parent e333968 commit 9ce2e3b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ mmapReadOnly(int fd, offset_type offset, size_type size)
#endif

const auto p = (char*)mmap(NULL, size, PROT_READ, MAP_FLAGS, fd, offset);
if (p == MAP_FAILED)
throw std::runtime_error(Formatter()
<< "Cannot mmap size " << size << " at off "
<< offset << " : " << strerror(errno));

if (p == MAP_FAILED) {
// mmap may fails for a lot of reason.
// Most of them (io error, too big size...) may not recoverable but some of
// them may be relative to mmap only and a "simple" read from the file would work.
// Let's throw a MMapException to fallback to read (and potentially fail again there).
throw MMapException();

Check warning on line 154 in src/file_reader.cpp

View check run for this annotation

Codecov / codecov/patch

src/file_reader.cpp#L154

Added line #L154 was not covered by tests
}
return p;
}

Expand Down

0 comments on commit 9ce2e3b

Please sign in to comment.