summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-02-25 17:18:17 +0000
committerfrosch <frosch@openttd.org>2012-02-25 17:18:17 +0000
commit3d381403a88387d1599c3a63dd0bdf9bb97a2911 (patch)
tree6012e7e4aa0c8598121050b7ae396c5ebf04ce9e /src
parente3c665a3cbcdd6c51de09a7d21f31bbe805e89c8 (diff)
downloadopenttd-3d381403a88387d1599c3a63dd0bdf9bb97a2911.tar.xz
(svn r23986) -Fix (r23889): Invalid reads when scaling an odd-sized sprite smaller.
Diffstat (limited to 'src')
-rw-r--r--src/spritecache.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/spritecache.cpp b/src/spritecache.cpp
index c77d3c546..4b705fc94 100644
--- a/src/spritecache.cpp
+++ b/src/spritecache.cpp
@@ -197,18 +197,19 @@ static void ResizeSpriteOut(SpriteLoader::Sprite *sprite, ZoomLevel zoom)
const SpriteLoader::CommonPixel *src_end = src + sprite[zoom - 1].height * sprite[zoom - 1].width;
for (uint y = 0; y < sprite[zoom].height; y++) {
- if (src >= src_end) src = src_end - sprite[zoom - 1].width;
-
- const SpriteLoader::CommonPixel *src_ln = src + sprite[zoom - 1].width * 2;
+ const SpriteLoader::CommonPixel *src_ln = src + sprite[zoom - 1].width;
+ assert(src_ln <= src_end);
for (uint x = 0; x < sprite[zoom].width; x++) {
- if (src >= src_ln) src = src_ln - 1;
- if ((src + 1)->a != 0) { *dst = *(src + 1); }
- else { *dst = *src; }
+ assert(src < src_ln);
+ if (src + 1 != src_ln && (src + 1)->a != 0) {
+ *dst = *(src + 1);
+ } else {
+ *dst = *src;
+ }
dst++;
src += 2;
}
-
- src = src_ln;
+ src = src_ln + sprite[zoom - 1].width;
}
}