aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-15 21:01:32 +0000
committerGravatar mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-15 21:01:32 +0000
commit0038c12f337b7037ef698e2723099c7e3b19c4ca (patch)
tree3a650feba7da7e408e310ac2d6dc8cef2a4ea096
parent439df286c89391f7e46c30d310cce4cb047dcd78 (diff)
Write NULL as "" so readString() always returns a non-NULL string.
BUG= R=reed@google.com Review URL: https://codereview.chromium.org/22862002 git-svn-id: http://skia.googlecode.com/svn/trunk@10754 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkWriter32.h4
-rw-r--r--src/core/SkWriter32.cpp11
-rw-r--r--tests/Writer32Test.cpp22
3 files changed, 7 insertions, 30 deletions
diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h
index 82cf346c8e..308e28897f 100644
--- a/include/core/SkWriter32.h
+++ b/include/core/SkWriter32.h
@@ -168,7 +168,9 @@ public:
* Writes a string to the writer, which can be retrieved with
* SkReader32::readString().
* The length can be specified, or if -1 is passed, it will be computed by
- * calling strlen(). The length must be < 0xFFFF
+ * calling strlen(). The length must be < max size_t.
+ *
+ * If you write NULL, it will be read as "".
*/
void writeString(const char* str, size_t len = (size_t)-1);
diff --git a/src/core/SkWriter32.cpp b/src/core/SkWriter32.cpp
index e41e2df0c4..ca21c5ad6d 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -246,12 +246,6 @@ void SkWriter32::validate() const {
const char* SkReader32::readString(size_t* outLen) {
size_t len = this->readInt();
- if (0xFFFF == len) {
- if (outLen) {
- *outLen = 0;
- }
- return NULL;
- }
const void* ptr = this->peek();
// skip over teh string + '\0' and then pad to a multiple of 4
@@ -275,9 +269,8 @@ size_t SkReader32::readIntoString(SkString* copy) {
void SkWriter32::writeString(const char str[], size_t len) {
if (NULL == str) {
- // We're already requiring len < 0xFFFF, so we can use that to mark NULL.
- this->write32(0xFFFF);
- return;
+ str = "";
+ len = 0;
}
if ((long)len < 0) {
len = strlen(str);
diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp
index 6ecfcf3eda..194164dd1c 100644
--- a/tests/Writer32Test.cpp
+++ b/tests/Writer32Test.cpp
@@ -24,29 +24,11 @@ static void check_contents(skiatest::Reporter* reporter, const SkWriter32& write
static void test_string_null(skiatest::Reporter* reporter) {
uint8_t storage[8];
SkWriter32 writer(0, storage, sizeof(storage));
- SkReader32 reader(storage, sizeof(storage));
-
- const char* str;
- size_t len;
// Can we write NULL?
writer.writeString(NULL);
- const int32_t null[] = { 0xFFFF };
- check_contents(reporter, writer, null, sizeof(null));
- str = reader.readString(&len);
- REPORTER_ASSERT(reporter, NULL == str);
- REPORTER_ASSERT(reporter, 0 == len);
-
- writer.reset(storage, sizeof(storage));
- reader.rewind();
-
- // Is NULL distinct from ""?
- writer.writeString("");
- const int32_t empty[] = { 0x0, 0x0 };
- check_contents(reporter, writer, empty, sizeof(empty));
- str = reader.readString(&len);
- REPORTER_ASSERT(reporter, 0 == strcmp("", str));
- REPORTER_ASSERT(reporter, 0 == len);
+ const int32_t expected[] = { 0x0, 0x0 };
+ check_contents(reporter, writer, expected, sizeof(expected));
}
static void test_rewind(skiatest::Reporter* reporter) {