diff options
author | Hal Canary <halcanary@google.com> | 2018-03-28 08:54:03 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-29 15:46:45 +0000 |
commit | c3bc425bd4d630f4c6b69f38473fc69b77a1d5b9 (patch) | |
tree | 6235b8f24619263e457941584b6bebae7b7f5c01 /src | |
parent | 20010e80b637b9c6173c2d3d3c2070bb3b184104 (diff) |
SkDynamicMemoryWStream: clean up, asserts, etc.
BUG=chromium:825476
Change-Id: Ied7d5e8313781821acc778d784ecade46b93ca22
Reviewed-on: https://skia-review.googlesource.com/116860
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkStream.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index 2c5e9eba2f..fef5aa8794 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -472,9 +472,9 @@ SkDynamicMemoryWStream::~SkDynamicMemoryWStream() { } void SkDynamicMemoryWStream::reset() { - Block* block = fHead; + Block* block = fHead; while (block != nullptr) { - Block* next = block->fNext; + Block* next = block->fNext; sk_free(block); block = next; } @@ -493,7 +493,8 @@ size_t SkDynamicMemoryWStream::bytesWritten() const { bool SkDynamicMemoryWStream::write(const void* buffer, size_t count) { if (count > 0) { - size_t size; + SkASSERT(buffer); + size_t size; if (fTail) { if (fTail->avail() > 0) { @@ -516,10 +517,11 @@ bool SkDynamicMemoryWStream::write(const void* buffer, size_t count) { block->init(size); block->append(buffer, count); - if (fTail != nullptr) + if (fTail != nullptr) { fTail->fNext = block; - else + } else { fHead = fTail = block; + } fTail = block; this->validate(); } @@ -536,8 +538,9 @@ bool SkDynamicMemoryWStream::read(void* buffer, size_t offset, size_t count) { if (offset < size) { size_t part = offset + count > size ? size - offset : count; memcpy(buffer, block->start() + offset, part); - if (count <= part) + if (count <= part) { return true; + } count -= part; buffer = (void*) ((char* ) buffer + part); } @@ -548,6 +551,7 @@ bool SkDynamicMemoryWStream::read(void* buffer, size_t offset, size_t count) { } void SkDynamicMemoryWStream::copyTo(void* dst) const { + SkASSERT(dst); Block* block = fHead; while (block != nullptr) { size_t size = block->written(); @@ -558,6 +562,7 @@ void SkDynamicMemoryWStream::copyTo(void* dst) const { } bool SkDynamicMemoryWStream::writeToStream(SkWStream* dst) const { + SkASSERT(dst); for (Block* block = fHead; block != nullptr; block = block->fNext) { if (!dst->write(block->start(), block->written())) { return false; @@ -583,6 +588,10 @@ void SkDynamicMemoryWStream::padToAlign4() { void SkDynamicMemoryWStream::copyToAndReset(void* ptr) { + if (!ptr) { + this->reset(); + return; + } // By looping through the source and freeing as we copy, we // can reduce real memory use with large streams. char* dst = reinterpret_cast<char*>(ptr); @@ -600,6 +609,7 @@ void SkDynamicMemoryWStream::copyToAndReset(void* ptr) { } bool SkDynamicMemoryWStream::writeToAndReset(SkWStream* dst) { + SkASSERT(dst); // By looping through the source and freeing as we copy, we // can reduce real memory use with large streams. bool dstStreamGood = true; |