diff --git a/simgear/io/sg_mmap.cxx b/simgear/io/sg_mmap.cxx index 5d2879e8..052c04ea 100644 --- a/simgear/io/sg_mmap.cxx +++ b/simgear/io/sg_mmap.cxx @@ -131,6 +131,10 @@ off_t SGMMapFile::forward(off_t amount) { amount = size - offset; } offset += amount; + + if (amount == 0) + eof_flag = true; + return amount; } @@ -138,8 +142,10 @@ const char* SGMMapFile::advance(off_t amount) { const char *ptr = buffer + offset; off_t advanced = forward(amount); - if (advanced != amount) + if (advanced != amount) { + eof_flag = true; return nullptr; + } return ptr; } diff --git a/simgear/io/sg_mmap.hxx b/simgear/io/sg_mmap.hxx index a330f1e7..a68d6dac 100644 --- a/simgear/io/sg_mmap.hxx +++ b/simgear/io/sg_mmap.hxx @@ -115,6 +115,9 @@ public: // get the pointer to the start of the buffer inline const char *get() { return buffer; } + // get the pointer to the current offset of the buffer + inline const char *ptr() { return buffer + offset; } + // get the pointer at the current offset and increase the offset by amount // returns nullptr if the offset pointer would end up beyond the mmap // buffer size