Skip to content

Commit

Permalink
fix error with mapped source
Browse files Browse the repository at this point in the history
  • Loading branch information
vuule committed Mar 26, 2021
1 parent fe20929 commit 0cce858
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cpp/src/io/utilities/datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class memory_mapped_source : public file_source {
explicit memory_mapped_source(const char *filepath, size_t offset, size_t size)
: file_source(filepath)
{
map(_file.desc(), offset, size);
if (_file.size() != 0) map(_file.desc(), offset, size);
}

virtual ~memory_mapped_source()
Expand Down Expand Up @@ -120,12 +120,12 @@ class memory_mapped_source : public file_source {
private:
void map(int fd, size_t offset, size_t size)
{
CUDF_EXPECTS(offset + size < _file.size(), "Mapped region is past end of file");
CUDF_EXPECTS(offset < _file.size(), "Offset is past end of file");

// Offset for `mmap()` must be page aligned
_map_offset = offset & ~(sysconf(_SC_PAGESIZE) - 1);

if (size == 0) { size = _file.size() - offset; }
if (size == 0 || (offset + size) > _file.size()) { size = _file.size() - offset; }

// Size for `mmap()` needs to include the page padding
_map_size = size + (offset - _map_offset);
Expand Down

0 comments on commit 0cce858

Please sign in to comment.