diff --git a/stream/filters/slice_stream.h b/stream/filters/slice_stream.h index d792b57d6..990092be7 100644 --- a/stream/filters/slice_stream.h +++ b/stream/filters/slice_stream.h @@ -55,7 +55,12 @@ class SliceStream : public Stream size_t size() const { return length; } const void *getPtr() { return getPtr(0, length); } - const void *getPtr(size_t size) { return getPtr(pos, size); } + const void *getPtr(size_t size) + { + void *ptr = getPtr(pos, size); + seek(pos+size); + return ptr; + } const void *getPtr(size_t pos, size_t size) { // Boundry checks on pos and size. Bounding the size is diff --git a/stream/servers/memory_stream.h b/stream/servers/memory_stream.h index d77779878..29bc476fc 100644 --- a/stream/servers/memory_stream.h +++ b/stream/servers/memory_stream.h @@ -71,9 +71,15 @@ class MemoryStream : public Stream size_t size() const { return length; } bool eof() const { return pos == length; } - /// Get the base pointer to the entire buffer const void *getPtr() { return data; } - const void *getPtr(size_t size) { return ((char*)data)+pos; } + const void *getPtr(size_t size) + { + // This variant of getPtr must move the position pointer + size_t opos = pos; + pos += size; + if(pos > length) pos = length; + return ((char*)data)+opos; + } const void *getPtr(size_t pos, size_t size) { if(pos > length) pos = length; diff --git a/stream/stream.h b/stream/stream.h index 309b0b33a..53e662341 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -60,13 +60,14 @@ class Stream /// memory-based streams where using them would be an optimization. virtual const void *getPtr() { assert(0); } - /// Get a pointer to a memory region of 'size' bytes from the - /// current position. - virtual const void *getPtr(size_t size) { assert(0); } - /// Get a pointer to a memory region of 'size' bytes starting from /// position 'pos' virtual const void *getPtr(size_t pos, size_t size) { assert(0); } + + /// Get a pointer to a memory region of 'size' bytes from the + /// current position. Unlike the two other getPtr variants, this + /// will advance the position past the returned area. + virtual const void *getPtr(size_t size) { assert(0); } }; typedef boost::shared_ptr StreamPtr;