From ea66347e830a6c28f31d6d46ba6c2bc0ae9232a7 Mon Sep 17 00:00:00 2001 From: mol123 <60134413+mol123@users.noreply.github.com> Date: Wed, 28 Aug 2024 11:46:37 +0200 Subject: [PATCH] Fix file size computation on 32-bit Windows. --- httplib.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/httplib.h b/httplib.h index 2a4b285..9d24d67 100644 --- a/httplib.h +++ b/httplib.h @@ -2851,7 +2851,13 @@ inline bool mmap::open(const char *path) { DWORD sizeLow; sizeLow = ::GetFileSize(hFile_, &sizeHigh); if (sizeLow == INVALID_FILE_SIZE) { return false; } - size_ = (static_cast(sizeHigh) << (sizeof(DWORD) * 8)) | sizeLow; + size_ = sizeLow; +#if defined(_WIN64) + size_ |= (static_cast(sizeHigh) << (sizeof(DWORD) * 8)); +#else + // The size of the file is too large to fit into `size_`, which is 32 bit. + if (sizeHigh != 0) { return false; } +#endif #endif #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) && \