fix a couple flaky nonnull attribute ubsan warnings
authormtklein <mtklein@chromium.org>
Wed, 9 Dec 2015 18:02:14 +0000 (10:02 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 9 Dec 2015 18:02:14 +0000 (10:02 -0800)
Errors this should fix:
  https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Debug-ASAN/builds/3779/steps/dm/logs/stdio
  https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Debug-ASAN/builds/3779/steps/nanobench/logs/stdio

CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Debug-ASAN-Trybot

TBR=reed@google.com
No API changes.

BUG=skia:

Review URL: https://codereview.chromium.org/1504313005

include/core/SkTypes.h
src/core/SkRecordDraw.cpp

index 6c2e6361530ac9674da7f69f7b2dd978bb80ce32..e4569f21b1c5a2e6e316c5549ba4ed98420386e3 100644 (file)
@@ -100,7 +100,10 @@ SK_API extern void* sk_calloc_throw(size_t size);
 
 // bzero is safer than memset, but we can't rely on it, so... sk_bzero()
 static inline void sk_bzero(void* buffer, size_t size) {
-    memset(buffer, 0, size);
+    // Please c.f. sk_careful_memcpy.  It's undefined behavior to call memset(null, 0, 0).
+    if (size) {
+        memset(buffer, 0, size);
+    }
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index 4847273f52a826f4eb2510abb75b4e7860cc82d2..b9bf92c0bad77b9a73ff7711d7e24b905e822491 100644 (file)
@@ -693,7 +693,8 @@ private:
             // Store 'saveLayer ops from enclosing picture' + drawPict op + 'ops from sub-picture'
             dst.fKeySize = fSaveLayerOpStack.count() + src.fKeySize + 1;
             dst.fKey = new int[dst.fKeySize];
-            memcpy(dst.fKey, fSaveLayerOpStack.begin(), fSaveLayerOpStack.count() * sizeof(int));
+            sk_careful_memcpy(dst.fKey, fSaveLayerOpStack.begin(),
+                              fSaveLayerOpStack.count() * sizeof(int));
             dst.fKey[fSaveLayerOpStack.count()] = fFillBounds.currentOp();
             memcpy(&dst.fKey[fSaveLayerOpStack.count()+1], src.fKey, src.fKeySize * sizeof(int));
         }