From 02046c50b294ae2b28e562b0e6e281e4ef823352 Mon Sep 17 00:00:00 2001 From: mtklein Date: Wed, 9 Dec 2015 10:02:14 -0800 Subject: [PATCH] fix a couple flaky nonnull attribute ubsan warnings 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 | 5 ++++- src/core/SkRecordDraw.cpp | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 6c2e636153..e4569f21b1 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -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); + } } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp index 4847273f52..b9bf92c0ba 100644 --- a/src/core/SkRecordDraw.cpp +++ b/src/core/SkRecordDraw.cpp @@ -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)); } -- 2.34.1