Ensure that SkMemoryStream does not crash dereferencing fData.
SkMemoryStream attempts to dereference fData in multiple places.
Instead of allowing it to be NULL, resulting in a crash, set it
to SkData::NewEmpty().
Add a test for SkStream that will crash when its SkData is set to NULL.
Review URL: https://codereview.appspot.com/7061059
git-svn-id: http://skia.googlecode.com/svn/trunk@7111 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/StreamTest.cpp b/tests/StreamTest.cpp
index b5e3cd9..ed51aa7 100644
--- a/tests/StreamTest.cpp
+++ b/tests/StreamTest.cpp
@@ -130,10 +130,29 @@
}
}
+// Test that setting an SkMemoryStream to a NULL data does not result in a crash when calling
+// methods that access fData.
+static void TestDereferencingData(SkMemoryStream* memStream) {
+ memStream->read(NULL, 0);
+ memStream->getMemoryBase();
+ SkAutoDataUnref data(memStream->copyToData());
+}
+
+static void TestNullData() {
+ SkData* nullData = NULL;
+ SkMemoryStream memStream(nullData);
+ TestDereferencingData(&memStream);
+
+ memStream.setData(nullData);
+ TestDereferencingData(&memStream);
+
+}
+
static void TestStreams(skiatest::Reporter* reporter) {
TestRStream(reporter);
TestWStream(reporter);
TestPackedUInt(reporter);
+ TestNullData();
}
#include "TestClassDef.h"