Index: src/utils/SkFrontBufferedStream.cpp |
diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp |
index 0955cfaf712b7c8296ab4eecb4cb36042a5698cc..e0b586a29d830fbfa00cbf5d954bbc5162ef0d46 100644 |
--- a/src/utils/SkFrontBufferedStream.cpp |
+++ b/src/utils/SkFrontBufferedStream.cpp |
@@ -16,7 +16,7 @@ public: |
size_t read(void* buffer, size_t size) override; |
- bool peek(void* buffer, size_t size) const override; |
+ size_t peek(void* buffer, size_t size) const override; |
bool isAtEnd() const override; |
@@ -157,18 +157,20 @@ size_t FrontBufferedStream::readDirectlyFromStream(char* dst, size_t size) { |
return bytesReadDirectly; |
} |
-bool FrontBufferedStream::peek(void* dst, size_t size) const { |
+size_t FrontBufferedStream::peek(void* dst, size_t size) const { |
// Keep track of the offset so we can return to it. |
const size_t start = fOffset; |
- if (start + size > fBufferSize) { |
- // This stream is not able to buffer enough. |
- return false; |
+ |
+ if (start >= fBufferSize) { |
+ // This stream is not able to buffer. |
+ return 0; |
} |
+ |
+ size = SkTMin(size, fBufferSize - start); |
FrontBufferedStream* nonConstThis = const_cast<FrontBufferedStream*>(this); |
- SkDEBUGCODE(const size_t bytesRead =) nonConstThis->read(dst, size); |
- SkASSERT(bytesRead == size); |
+ const size_t bytesRead = nonConstThis->read(dst, size); |
nonConstThis->fOffset = start; |
- return true; |
+ return bytesRead; |
} |
size_t FrontBufferedStream::read(void* voidDst, size_t size) { |