vimpunk / mio

Cross-platform C++11 header-only library for memory mapped file IO
MIT License
1.71k stars 157 forks source link

Fix memory mapped data offset #47

Closed MambaWong closed 5 years ago

MambaWong commented 5 years ago

I think the virtual address maybe like this: ctx.data = mapping_start + offset - aligned_offset;

vimpunk commented 5 years ago

Hi @MambaWong, thank you for the PR! You're right, this was a silly oversight on my part. Thanks for fixing!

privefl commented 5 years ago

Is this making use of memory map wrong in some way?

vimpunk commented 5 years ago

@privefl Not any more, thankfully. But it was a serious bug in that if the caller specified an offset larger than the page size, the returned pointer would point to the wrong place... I guess I never really used the offset based approach and thus never noticed this, but I'm still baffled I let this slip in. Sorry!

I will add tests that test mapping at offsets that are larger than the system page size.