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

Side by Side Diff: include/core/SkTSearch.h

Issue 1362613002: Fix possible integer overflow in SkTSearch's midpoint calculation (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Fix operator precedence Created 5 years, 2 months 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 | « no previous file | no next file » | 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 #ifndef SkTSearch_DEFINED 10 #ifndef SkTSearch_DEFINED
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 if (count <= 0) { 42 if (count <= 0) {
43 return ~0; 43 return ~0;
44 } 44 }
45 45
46 SkASSERT(base != NULL); // base may be NULL if count is zero 46 SkASSERT(base != NULL); // base may be NULL if count is zero
47 47
48 int lo = 0; 48 int lo = 0;
49 int hi = count - 1; 49 int hi = count - 1;
50 50
51 while (lo < hi) { 51 while (lo < hi) {
52 int mid = (hi + lo) >> 1; 52 int mid = lo + ((hi - lo) >> 1);
53 const T* elem = (const T*)((const char*)base + mid * elemSize); 53 const T* elem = (const T*)((const char*)base + mid * elemSize);
54 54
55 if (less(*elem, key)) 55 if (less(*elem, key))
56 lo = mid + 1; 56 lo = mid + 1;
57 else 57 else
58 hi = mid; 58 hi = mid;
59 } 59 }
60 60
61 const T* elem = (const T*)((const char*)base + hi * elemSize); 61 const T* elem = (const T*)((const char*)base + hi * elemSize);
62 if (less(*elem, key)) { 62 if (less(*elem, key)) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 enum { 137 enum {
138 STORAGE = 64 138 STORAGE = 64
139 }; 139 };
140 char fStorage[STORAGE+1]; 140 char fStorage[STORAGE+1];
141 }; 141 };
142 142
143 // Helper when calling qsort with a compare proc that has typed its arguments 143 // Helper when calling qsort with a compare proc that has typed its arguments
144 #define SkCastForQSort(compare) reinterpret_cast<int (*)(const void*, const void *)>(compare) 144 #define SkCastForQSort(compare) reinterpret_cast<int (*)(const void*, const void *)>(compare)
145 145
146 #endif 146 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698