From 0f07082a78355b8607bf04dd4e1ba42e14fc636f Mon Sep 17 00:00:00 2001 From: David Turner Date: Mon, 24 Jan 2011 01:58:43 +0000 Subject: PARALLACTION: Improve safety of PathBuffer::getValue(). This will now avoid invalid memory reads and instead emit warnings if it is called with values outside of the expected data buffer or on a NULL buffer. svn-id: r55492 --- engines/parallaction/graphics.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'engines/parallaction') diff --git a/engines/parallaction/graphics.cpp b/engines/parallaction/graphics.cpp index 2990d024d2..0e6f10f6af 100644 --- a/engines/parallaction/graphics.cpp +++ b/engines/parallaction/graphics.cpp @@ -1110,7 +1110,15 @@ void PathBuffer::free() { } byte PathBuffer::getValue(uint16 x, uint16 y) const { - byte m = data[(x >> 3) + y * internalWidth]; + byte m = 0; + if (data) { + uint index = (x >> 3) + y * internalWidth; + if (index < size) + m = data[index]; + else + warning("PathBuffer::getValue(x: %d, y: %d) outside of data buffer of size %d", x, y, size); + } else + warning("PathBuffer::getValue() attempted to use NULL data buffer"); uint bit = bigEndian ? (x & 7) : (7 - (x & 7)); return ((1 << bit) & m) >> bit; } -- cgit v1.2.3