aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorSven Hesse2011-01-27 20:38:58 +0000
committerSven Hesse2011-01-27 20:38:58 +0000
commitecd2e0f3a04066abd0c4ca332c4d078f06d3b4b5 (patch)
treed8514638c5f6007ddb67d68ed141a41a75d48306 /engines
parent57dc8f6fc264597bbc80faba4a837f22ff145691 (diff)
downloadscummvm-rg350-ecd2e0f3a04066abd0c4ca332c4d078f06d3b4b5.tar.gz
scummvm-rg350-ecd2e0f3a04066abd0c4ca332c4d078f06d3b4b5.tar.bz2
scummvm-rg350-ecd2e0f3a04066abd0c4ca332c4d078f06d3b4b5.zip
GOB: Add sanity checks to Pixel and ConstPixel
svn-id: r55571
Diffstat (limited to 'engines')
-rw-r--r--engines/gob/surface.cpp27
-rw-r--r--engines/gob/surface.h6
2 files changed, 27 insertions, 6 deletions
diff --git a/engines/gob/surface.cpp b/engines/gob/surface.cpp
index 9de0d22939..d621ce5a97 100644
--- a/engines/gob/surface.cpp
+++ b/engines/gob/surface.cpp
@@ -40,12 +40,17 @@ static void plotPixel(int x, int y, int color, void *data) {
}
-Pixel::Pixel(byte *vidMem, uint8 bpp) : _vidMem(vidMem), _bpp(bpp) {
+Pixel::Pixel(byte *vidMem, uint8 bpp, byte *min, byte *max) :
+ _vidMem(vidMem), _bpp(bpp), _min(min), _max(max) {
+
assert((_bpp == 1) || (_bpp == 2));
+ assert(_vidMem >= _min);
+ assert(_vidMem < _max);
}
Pixel &Pixel::operator++() {
_vidMem += _bpp;
+
return *this;
}
@@ -77,6 +82,9 @@ Pixel &Pixel::operator-=(int x) {
}
uint32 Pixel::get() const {
+ assert(_vidMem >= _min);
+ assert(_vidMem < _max);
+
if (_bpp == 1)
return *((byte *) _vidMem);
if (_bpp == 2)
@@ -86,6 +94,9 @@ uint32 Pixel::get() const {
}
void Pixel::set(uint32 p) {
+ assert(_vidMem >= _min);
+ assert(_vidMem < _max);
+
if (_bpp == 1)
*((byte *) _vidMem) = (byte) p;
if (_bpp == 2)
@@ -93,10 +104,15 @@ void Pixel::set(uint32 p) {
}
-ConstPixel::ConstPixel(const byte *vidMem, uint8 bpp) : _vidMem(vidMem), _bpp(bpp) {
+ConstPixel::ConstPixel(const byte *vidMem, uint8 bpp, const byte *min, const byte *max) :
+ _vidMem(vidMem), _bpp(bpp), _min(min), _max(max) {
+
assert((_bpp == 1) || (_bpp == 2));
+ assert(_vidMem >= _min);
+ assert(_vidMem < _max);
}
+
ConstPixel &ConstPixel::operator++() {
_vidMem += _bpp;
return *this;
@@ -130,6 +146,9 @@ ConstPixel &ConstPixel::operator-=(int x) {
}
uint32 ConstPixel::get() const {
+ assert(_vidMem >= _min);
+ assert(_vidMem < _max);
+
if (_bpp == 1)
return *((const byte *) _vidMem);
if (_bpp == 2)
@@ -213,13 +232,13 @@ const byte *Surface::getData(uint16 x, uint16 y) const {
Pixel Surface::get(uint16 x, uint16 y) {
byte *vidMem = getData(x, y);
- return Pixel(vidMem, _bpp);
+ return Pixel(vidMem, _bpp, _vidMem, _vidMem + _height * _width * _bpp);
}
ConstPixel Surface::get(uint16 x, uint16 y) const {
const byte *vidMem = getData(x, y);
- return ConstPixel(vidMem, _bpp);
+ return ConstPixel(vidMem, _bpp, _vidMem, _vidMem + _height * _width * _bpp);
}
bool Surface::clipBlitRect(int16 &left, int16 &top, int16 &right, int16 &bottom, int16 &x, int16 &y,
diff --git a/engines/gob/surface.h b/engines/gob/surface.h
index 89e91975a2..b8426989f3 100644
--- a/engines/gob/surface.h
+++ b/engines/gob/surface.h
@@ -35,7 +35,7 @@ namespace Gob {
/** An iterator over a surface's image data, automatically handles different color depths. */
class Pixel {
public:
- Pixel(byte *vidMem, uint8 bpp);
+ Pixel(byte *vidMem, uint8 bpp, byte *min, byte *max);
Pixel &operator++();
Pixel operator++(int x);
@@ -51,13 +51,14 @@ public:
private:
byte *_vidMem;
+ byte *_min, *_max;
uint8 _bpp;
};
/** A const iterator over a surface's image data, automatically handles different color depths. */
class ConstPixel {
public:
- ConstPixel(const byte *vidMem, uint8 bpp);
+ ConstPixel(const byte *vidMem, uint8 bpp, const byte *min, const byte *max);
ConstPixel &operator++();
ConstPixel operator++(int x);
@@ -72,6 +73,7 @@ public:
private:
const byte *_vidMem;
+ const byte *_min, *_max;
uint8 _bpp;
};