Fix memory corruption bug in lcscreen::load()

lcscren::load() didn't compute the number of pixels to load correctly.
The data has 2 byte header followed by 3 byte pixels, meaning the number
of pixels is (size - 2) / 3. But the code assumed 2 byte pixels, causing
load loop to trash memory after end of screen memory.
This commit is contained in:
Ilari Liusvaara 2011-11-09 19:48:58 +02:00
parent 85d00b243e
commit f65e0b7139

View file

@ -416,7 +416,7 @@ void lcscreen::load(const std::vector<char>& data) throw(std::bad_alloc, std::ru
width = _width;
height = _height;
pitch = width;
for(size_t i = 0; i < (data.size() - 2) / 2; i++)
for(size_t i = 0; i < (data.size() - 2) / 3; i++)
mem[i] = static_cast<uint32_t>(data2[2 + 3 * i]) * 65536 +
static_cast<uint32_t>(data2[2 + 3 * i + 1]) * 256 +
static_cast<uint32_t>(data2[2 + 3 * i + 2]);