Skip to content

Commit

Permalink
fix windows mmap of empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Jan 23, 2025
1 parent e2e5512 commit f2739b8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ file_mapping::file_mapping(file_handle file, open_mode_t const mode
: m_size(memory_map_size(mode, file_size, file))
, m_file(std::move(file), mode, m_size)
, m_open_unmap_lock(std::move(open_unmap_lock))
, m_mapping((mode & open_mode::no_mmap) ? nullptr
, m_mapping((mode & open_mode::no_mmap) || m_size == 0 ? nullptr
: MapViewOfFile(m_file.handle(), map_access(mode), 0, 0, static_cast<std::size_t>(m_size)))
{
// you can't create an mmap of size 0, so we just set it to null. We
// still need to create the empty file.
if (!(mode & open_mode::no_mmap) && m_mapping == nullptr)
if (!(mode & open_mode::no_mmap) && m_size > 0 && m_mapping == nullptr)
throw_ex<storage_error>(error_code(GetLastError(), system_category()), operation_t::file_mmap);
}

Expand Down

0 comments on commit f2739b8

Please sign in to comment.