Make span_util.h wrappers completely compliant with ubsan.

Skirt the memcpy(0, 0, 0) issue and be completely conforming with
spec since the pointers are marked non-null.

Bug: pdfium:2066
Change-Id: I31e1cb3e9a8a69b2e2039e3516a0f97f7658b5ba
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/109910
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/span_util.h b/core/fxcrt/span_util.h
index c911617..99fc25c 100644
--- a/core/fxcrt/span_util.h
+++ b/core/fxcrt/span_util.h
@@ -17,8 +17,10 @@
           typename U,
           typename = pdfium::internal::EnableIfLegalSpanConversion<T, U>>
 void spancpy(pdfium::span<T> dst, pdfium::span<U> src) {
-  CHECK_GE(dst.size_bytes(), src.size_bytes());
-  memcpy(dst.data(), src.data(), src.size_bytes());
+  if (src.size_bytes()) {
+    CHECK_GE(dst.size_bytes(), src.size_bytes());
+    memcpy(dst.data(), src.data(), src.size_bytes());
+  }
 }
 
 // Bounds-checked moves from spans into spans.
@@ -26,20 +28,26 @@
           typename U,
           typename = pdfium::internal::EnableIfLegalSpanConversion<T, U>>
 void spanmove(pdfium::span<T> dst, pdfium::span<U> src) {
-  CHECK_GE(dst.size_bytes(), src.size_bytes());
-  memmove(dst.data(), src.data(), src.size_bytes());
+  if (src.size_bytes()) {
+    CHECK_GE(dst.size_bytes(), src.size_bytes());
+    memmove(dst.data(), src.data(), src.size_bytes());
+  }
 }
 
 // Bounds-checked sets into spans.
 template <typename T>
 void spanset(pdfium::span<T> dst, uint8_t val) {
-  memset(dst.data(), val, dst.size_bytes());
+  if (dst.size_bytes()) {
+    memset(dst.data(), val, dst.size_bytes());
+  }
 }
 
 // Bounds-checked zeroing of spans.
 template <typename T>
 void spanclr(pdfium::span<T> dst) {
-  memset(dst.data(), 0, dst.size_bytes());
+  if (dst.size_bytes()) {
+    memset(dst.data(), 0, dst.size_bytes());
+  }
 }
 
 }  // namespace fxcrt