[skjson] Fix ASAN undefined behavior

ASAN opines that a nullptr memcpy dest is undefined behavior, even when
n == 0.  ASAN may be right.

This doesn't occur internally, in the parser, but can be triggered with
the DOM builder API (as do some tests currently).

We could say "don't do that", but if someone wants to build an empty
string/array/object, it's kind of awkward to force them to provide a
valid source pointer instead of simply e.g. Array(nullptr, 0).

So let's guard for this case to make ASAN happy.

Change-Id: If12e39f5eb8b273f22bbb0b5fce3321bf6482173
Reviewed-on: https://skia-review.googlesource.com/134944
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/modules/skjson/src/SkJSON.cpp b/modules/skjson/src/SkJSON.cpp
index e0a8f43..64f1302 100644
--- a/modules/skjson/src/SkJSON.cpp
+++ b/modules/skjson/src/SkJSON.cpp
@@ -82,9 +82,12 @@
     // The Ts are already in memory, so their size should be safe.
     const auto total_size = sizeof(size_t) + size * sizeof(T) + extra_alloc_size;
     auto* size_ptr = reinterpret_cast<size_t*>(alloc.makeBytesAlignedTo(total_size, kRecAlign));
-    auto* data_ptr = reinterpret_cast<void*>(size_ptr + 1);
     *size_ptr = size;
-    memcpy(data_ptr, src, size * sizeof(T));
+
+    if (size) {
+        auto* data_ptr = reinterpret_cast<void*>(size_ptr + 1);
+        memcpy(data_ptr, src, size * sizeof(T));
+    }
 
     return size_ptr;
 }
@@ -121,8 +124,10 @@
     this->init_tagged(Tag::kShortString);
 
     auto* payload = this->cast<char>();
-    memcpy(payload, src, size);
-    payload[size] = '\0';
+    if (size) {
+        memcpy(payload, src, size);
+        payload[size] = '\0';
+    }
 
     const auto len_tag = SkTo<char>(kMaxInlineStringSize - size);
     // This technically overwrites the tag, but is safe because