aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2014-05-03 12:45:42 +1000
committerNeil <nyamatongwe@gmail.com>2014-05-03 12:45:42 +1000
commit32bc0408823cd0108a8990d80c1f45259e99a0cb (patch)
tree6726d621e7a62c341b070c89c5bf5275a6c395e5 /src
parentc49e3a21e7ea2de856754fe44ef83028977c0a84 (diff)
downloadscintilla-mirror-32bc0408823cd0108a8990d80c1f45259e99a0cb.tar.gz
Using unsigned int for cache index to avoid casts and potential for failure.
Diffstat (limited to 'src')
-rw-r--r--src/PositionCache.cxx9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index 820fd4895..5f3fd03de 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -646,18 +646,18 @@ void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned
const char *s, unsigned int len, XYPOSITION *positions, Document *pdoc) {
allClear = false;
- int probe = -1;
+ unsigned int probe = pces.size(); // Out of bounds
if ((!pces.empty()) && (len < 30)) {
// Only store short strings in the cache so it doesn't churn with
// long comments with only a single comment.
// Two way associative: try two probe positions.
unsigned int hashValue = PositionCacheEntry::Hash(styleNumber, s, len);
- probe = static_cast<int>(hashValue % pces.size());
+ probe = hashValue % pces.size();
if (pces[probe].Retrieve(styleNumber, s, len, positions)) {
return;
}
- int probe2 = static_cast<int>((hashValue * 37) % pces.size());
+ unsigned int probe2 = (hashValue * 37) % pces.size();
if (pces[probe2].Retrieve(styleNumber, s, len, positions)) {
return;
}
@@ -682,7 +682,8 @@ void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned
} else {
surface->MeasureWidths(vstyle.styles[styleNumber].font, s, len, positions);
}
- if (probe >= 0) {
+ if (probe < pces.size()) {
+ // Store into cache
clock++;
if (clock > 60000) {
// Since there are only 16 bits for the clock, wrap it round and