Skip to content

Commit 06c6e4a

Browse files
committed
crop offset
1 parent 5109b75 commit 06c6e4a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cpp/MMapFile.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,12 @@ class MMapFile {
292292

293293
// compute page-aligned offset and length
294294
size_t pageSize = sysconf(_SC_PAGE_SIZE);
295-
size_t alignedOffset = offset - (offset % pageSize);
295+
size_t alignedOffset = offset;
296+
if (alignedOffset >= size_) [[unlikely]] {
297+
alignedOffset = size_; // Adjust alignedOffset to not exceed the size of the file
298+
}
299+
alignedOffset -= (alignedOffset % pageSize); // Align to page size
300+
296301
length += (offset - alignedOffset);
297302
if (alignedOffset + length > size_) [[unlikely]] {
298303
length = size_ - alignedOffset; // Adjust length to not exceed the size of the file

0 commit comments

Comments
 (0)