diff options
author | frosch <frosch@openttd.org> | 2009-12-03 15:27:33 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-12-03 15:27:33 +0000 |
commit | 169141433a100c34a79f766fcfceb41037fea04f (patch) | |
tree | a527826b12be3f25b89a91949d37b86a4be14369 /src/spriteloader | |
parent | 3addf58f30c2dd4fa850611af11d7a897989722b (diff) | |
download | openttd-169141433a100c34a79f766fcfceb41037fea04f.tar.xz |
(svn r18391) -Fix (r0): (Invalid) GRFs could trigger invalid reads.
Diffstat (limited to 'src/spriteloader')
-rw-r--r-- | src/spriteloader/grf.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/spriteloader/grf.cpp b/src/spriteloader/grf.cpp index 3b1ccc5f3..4600c4225 100644 --- a/src/spriteloader/grf.cpp +++ b/src/spriteloader/grf.cpp @@ -127,7 +127,11 @@ bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, } for (int x = 0; x < length; x++) { - data->m = ((sprite_type == ST_NORMAL && _palette_remap_grf[file_slot]) ? _palette_remap[*dest] : *dest); + switch (sprite_type) { + case ST_NORMAL: data->m = _palette_remap_grf[file_slot] ? _palette_remap[*dest] : *dest; break; + case ST_FONT: data->m = min(*dest, 2u); break; + default: data->m = *dest; break; + } dest++; data++; } @@ -148,7 +152,11 @@ bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, dest = dest_orig; for (int i = 0; i < sprite->width * sprite->height; i++) { - sprite->data[i].m = ((sprite_type == ST_NORMAL && _palette_remap_grf[file_slot]) ? _palette_remap[dest[i]] : dest[i]); + switch (sprite_type) { + case ST_NORMAL: sprite->data[i].m = _palette_remap_grf[file_slot] ? _palette_remap[dest[i]] : dest[i]; break; + case ST_FONT: sprite->data[i].m = min(dest[i], 2u); break; + default: sprite->data[i].m = dest[i]; break; + } } } |