Fix ASAN error for wbmp swizzles BUG=skia: Review URL: https://codereview.chromium.org/1269413006
diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp index f8e89c7..4da862f 100644 --- a/src/codec/SkSwizzler.cpp +++ b/src/codec/SkSwizzler.cpp
@@ -43,10 +43,12 @@ // Finish the remaining bits width &= 7; - U8CPU currByte = src[i]; - for (int j = 0; j < width; j++) { - dst[j] = ((currByte >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; - currByte <<= 1; + if (width > 0) { + U8CPU currByte = src[i]; + for (int j = 0; j < width; j++) { + dst[j] = ((currByte >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; + currByte <<= 1; + } } return SkSwizzler::kOpaque_ResultAlpha; } @@ -72,10 +74,12 @@ // Finish the remaining bits width &= 7; - U8CPU currByte = src[i]; - for (int j = 0; j < width; j++) { - dst[j] = ((currByte >> 7) & 1); - currByte <<= 1; + if (width > 0) { + U8CPU currByte = src[i]; + for (int j = 0; j < width; j++) { + dst[j] = ((currByte >> 7) & 1); + currByte <<= 1; + } } return SkSwizzler::kOpaque_ResultAlpha; } @@ -98,10 +102,12 @@ // Finish the remaining bits width &= 7; - U8CPU currByte = src[i]; - for (int j = 0; j < width; j++) { - dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK; - currByte <<= 1; + if (width > 0) { + U8CPU currByte = src[i]; + for (int j = 0; j < width; j++) { + dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK; + currByte <<= 1; + } } return SkSwizzler::kOpaque_ResultAlpha; }