diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2015-11-12 22:42:24 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2015-11-12 22:42:24 +0900 |
| commit | 3974c1223b19a8647d7e361fa130d0fa78a41026 (patch) | |
| tree | 4cd9f9585cb2939ecef37a3d215ab59f4df6f751 /src/AbstractDiskWriter.cc | |
| parent | af98861aff50737f87d9c251ee9a68280bba3e64 (diff) | |
Don't enable mmap if file allocation is disabled
Without file allocation, we cannot map file because file length could
be zero.
This could fix bug reported at GH-478
Diffstat (limited to 'src/AbstractDiskWriter.cc')
| -rw-r--r-- | src/AbstractDiskWriter.cc | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 0944194c..0d1e014a 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -284,12 +284,10 @@ ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len, int64_t offset) { if(mapaddr_) { - ssize_t readlen; - if(offset > maplen_) { - readlen = 0; - } else { - readlen = std::min(static_cast<size_t>(maplen_ - offset), len); + if (offset >= maplen_) { + return 0; } + auto readlen = std::min(maplen_ - offset, static_cast<int64_t>(len)); memcpy(data, mapaddr_ + offset, readlen); return readlen; } else { @@ -355,6 +353,14 @@ void AbstractDiskWriter::ensureMmapWrite(size_t len, int64_t offset) } } else { int64_t filesize = size(); + + if (filesize == 0) { + // mapping 0 length file is useless. Also munmap with size == + // 0 will fail with EINVAL. + enableMmap_ = false; + return; + } + int errNum = 0; if(static_cast<int64_t>(len + offset) <= filesize) { #ifdef __MINGW32__ |
