SkBlockMemoryStream: correct test in getMemoryBase().

The test "nullptr == fBlockMemory->fHead->fNext" tests that
all of the data is in one block, but it is also necessary to
test "fBlockMemory->fHead" to ensure that there is a first
block with data in it.

Review URL: https://codereview.chromium.org/1374493002
This commit is contained in:
halcanary 2015-09-28 07:29:39 -07:00 committed by Commit bot
parent f1b7a1d828
commit 209c1624ad
2 changed files with 9 additions and 2 deletions

View File

@ -795,7 +795,8 @@ public:
}
const void* getMemoryBase() override {
if (nullptr == fBlockMemory->fHead->fNext) {
if (nullptr != fBlockMemory->fHead &&
nullptr == fBlockMemory->fHead->fNext) {
return fBlockMemory->fHead->start();
}
return nullptr;

View File

@ -391,5 +391,11 @@ DEF_TEST(StreamCopy, reporter) {
stream_copy_test(reporter, src, N, &dumbStream);
SkMemoryStream smartStream(src.get(), (size_t)N);
stream_copy_test(reporter, src, N, &smartStream);
}
DEF_TEST(StreamEmptyStreamMemoryBase, r) {
SkDynamicMemoryWStream tmp;
SkAutoTDelete<SkStreamAsset> asset(tmp.detachAsStream());
REPORTER_ASSERT(r, nullptr == asset->getMemoryBase());
}