diff options
author | Ben Wagner <bungeman@google.com> | 2018-07-18 14:10:30 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-07-18 18:51:32 +0000 |
commit | 0afc75e7548bcb623132afa7cf7c8df179359151 (patch) | |
tree | b8fc8769418fafeb3aee7c976ea172730ae9a569 /src/core/SkPaintPriv.cpp | |
parent | 715d08c381b4cc8af33d7dcdefc9533dcc97e4c9 (diff) |
SkUTF16_CountUnichars to error instead of assert.
Update SkUTF16_CountUnichars to return -1 on invalid input instead of
simply asserting in debug. This also removes the unneeded checks for
zero length input. This also updates SkPaintPriv::ValidCountText and its
documentation to reflect the reality that it returns -1 on invalid data.
Bug: skia:8156
Change-Id: Ief227b7dec9d1e823b93e9061558f8412791fc09
Reviewed-on: https://skia-review.googlesource.com/142168
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/core/SkPaintPriv.cpp')
-rw-r--r-- | src/core/SkPaintPriv.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp index 9cd5e4708d..3be1ebeafa 100644 --- a/src/core/SkPaintPriv.cpp +++ b/src/core/SkPaintPriv.cpp @@ -91,19 +91,16 @@ bool SkPaintPriv::ShouldDither(const SkPaint& p, SkColorType dstCT) { } int SkPaintPriv::ValidCountText(const void* text, size_t length, SkPaint::TextEncoding encoding) { - if (length == 0) { - return 0; - } switch (encoding) { case SkPaint::kUTF8_TextEncoding: return SkUTF8_CountUnichars(text, length); case SkPaint::kUTF16_TextEncoding: return SkUTF16_CountUnichars(text, length); case SkPaint::kUTF32_TextEncoding: return SkUTF32_CountUnichars(text, length); case SkPaint::kGlyphID_TextEncoding: - if (SkIsAlign2(intptr_t(text)) && SkIsAlign2(length)) { - return length >> 1; + if (!SkIsAlign2(intptr_t(text)) || !SkIsAlign2(length)) { + return -1; } - break; + return length >> 1; } - return 0; + return -1; } |