aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkData.h4
-rw-r--r--src/core/SkData.cpp9
2 files changed, 9 insertions, 4 deletions
diff --git a/include/core/SkData.h b/include/core/SkData.h
index f24cf9c92c..61b52c5480 100644
--- a/include/core/SkData.h
+++ b/include/core/SkData.h
@@ -69,7 +69,9 @@ public:
/**
* Create a new dataref by copying the specified c-string
- * (a null-terminated array of bytes).
+ * (a null-terminated array of bytes). The returned SkData will have size()
+ * equal to strlen(cstr) + 1. If cstr is NULL, it will be treated the same
+ * as "".
*/
static SkData* NewWithCString(const char cstr[]);
diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp
index 2653f327c0..496d599379 100644
--- a/src/core/SkData.cpp
+++ b/src/core/SkData.cpp
@@ -112,10 +112,13 @@ SkData* SkData::NewSubset(const SkData* src, size_t offset, size_t length) {
}
SkData* SkData::NewWithCString(const char cstr[]) {
- if (NULL == cstr || 0 == cstr[0]) {
- return NewEmpty();
+ size_t size;
+ if (NULL == cstr) {
+ cstr = "";
+ size = 1;
} else {
- return NewWithCopy(cstr, strlen(cstr));
+ size = strlen(cstr) + 1;
}
+ return NewWithCopy(cstr, size);
}