Add flate compression test and fix bugs.
Review URL: http://codereview.appspot.com/3393041
git-svn-id: http://skia.googlecode.com/svn/trunk@628 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkFlate.cpp b/src/core/SkFlate.cpp
index a9adece..ade1658 100644
--- a/src/core/SkFlate.cpp
+++ b/src/core/SkFlate.cpp
@@ -56,7 +56,7 @@
uint8_t* input = (uint8_t*)src->getMemoryBase();
size_t inputLength = src->getLength();
- if (input == NULL || inputLength < 0) {
+ if (input == NULL || inputLength == 0) {
input = NULL;
flateData.next_in = inputBuffer;
flateData.avail_in = 0;
@@ -75,6 +75,8 @@
flateData.next_out = outputBuffer;
flateData.avail_out = kBufferSize;
}
+ if (rc != Z_OK)
+ break;
if (flateData.avail_in == 0) {
if (input != NULL)
break;
@@ -88,15 +90,13 @@
rc = deflate(&flateData, Z_NO_FLUSH);
else
rc = inflate(&flateData, Z_NO_FLUSH);
- if (rc != Z_OK)
- break;
}
while (rc == Z_OK) {
if (compress)
rc = deflate(&flateData, Z_FINISH);
else
rc = inflate(&flateData, Z_FINISH);
- if (flateData.avail_out > 0) {
+ if (flateData.avail_out < kBufferSize) {
if (!dst->write(outputBuffer, kBufferSize - flateData.avail_out))
return false;
flateData.next_out = outputBuffer;