Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: src/core/SkUtils.cpp

Issue 1503423003: ubsan shift fixes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add cast to work around win compiler Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkScan_Path.cpp ('k') | src/effects/gradients/SkClampRange.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkUtils.h" 10 #include "SkUtils.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 SkASSERT(utf8); 67 SkASSERT(utf8);
68 68
69 const uint8_t* p = (const uint8_t*)utf8; 69 const uint8_t* p = (const uint8_t*)utf8;
70 int c = *p; 70 int c = *p;
71 int hic = c << 24; 71 int hic = c << 24;
72 72
73 assert_utf8_leadingbyte(c); 73 assert_utf8_leadingbyte(c);
74 74
75 if (hic < 0) { 75 if (hic < 0) {
76 uint32_t mask = (uint32_t)~0x3F; 76 uint32_t mask = (uint32_t)~0x3F;
77 hic <<= 1; 77 hic = SkLeftShift(hic, 1);
78 do { 78 do {
79 c = (c << 6) | (*++p & 0x3F); 79 c = (c << 6) | (*++p & 0x3F);
80 mask <<= 5; 80 mask <<= 5;
81 } while ((hic <<= 1) < 0); 81 } while ((hic = SkLeftShift(hic, 1)) < 0);
82 c &= ~mask; 82 c &= ~mask;
83 } 83 }
84 return c; 84 return c;
85 } 85 }
86 86
87 SkUnichar SkUTF8_NextUnichar(const char** ptr) { 87 SkUnichar SkUTF8_NextUnichar(const char** ptr) {
88 SkASSERT(ptr && *ptr); 88 SkASSERT(ptr && *ptr);
89 89
90 const uint8_t* p = (const uint8_t*)*ptr; 90 const uint8_t* p = (const uint8_t*)*ptr;
91 int c = *p; 91 int c = *p;
92 int hic = c << 24; 92 int hic = c << 24;
93 93
94 assert_utf8_leadingbyte(c); 94 assert_utf8_leadingbyte(c);
95 95
96 if (hic < 0) { 96 if (hic < 0) {
97 uint32_t mask = (uint32_t)~0x3F; 97 uint32_t mask = (uint32_t)~0x3F;
98 hic <<= 1; 98 hic = SkLeftShift(hic, 1);
99 do { 99 do {
100 c = (c << 6) | (*++p & 0x3F); 100 c = (c << 6) | (*++p & 0x3F);
101 mask <<= 5; 101 mask <<= 5;
102 } while ((hic <<= 1) < 0); 102 } while ((hic = SkLeftShift(hic, 1)) < 0);
103 c &= ~mask; 103 c &= ~mask;
104 } 104 }
105 *ptr = (char*)p + 1; 105 *ptr = (char*)p + 1;
106 return c; 106 return c;
107 } 107 }
108 108
109 SkUnichar SkUTF8_PrevUnichar(const char** ptr) { 109 SkUnichar SkUTF8_PrevUnichar(const char** ptr) {
110 SkASSERT(ptr && *ptr); 110 SkASSERT(ptr && *ptr);
111 111
112 const char* p = *ptr; 112 const char* p = *ptr;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 271 }
272 } else { 272 } else {
273 char* start = utf8; 273 char* start = utf8;
274 while (utf16 < stop) { 274 while (utf16 < stop) {
275 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); 275 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8);
276 } 276 }
277 size = utf8 - start; 277 size = utf8 - start;
278 } 278 }
279 return size; 279 return size;
280 } 280 }
OLDNEW
« no previous file with comments | « src/core/SkScan_Path.cpp ('k') | src/effects/gradients/SkClampRange.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698