[Scummvm-cvs-logs] SF.net SVN: scummvm:[55571] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Thu Jan 27 21:38:58 CET 2011


Revision: 55571
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55571&view=rev
Author:   drmccoy
Date:     2011-01-27 20:38:58 +0000 (Thu, 27 Jan 2011)

Log Message:
-----------
GOB: Add sanity checks to Pixel and ConstPixel

Modified Paths:
--------------
    scummvm/trunk/engines/gob/surface.cpp
    scummvm/trunk/engines/gob/surface.h

Modified: scummvm/trunk/engines/gob/surface.cpp
===================================================================
--- scummvm/trunk/engines/gob/surface.cpp	2011-01-27 19:20:27 UTC (rev 55570)
+++ scummvm/trunk/engines/gob/surface.cpp	2011-01-27 20:38:58 UTC (rev 55571)
@@ -40,12 +40,17 @@
 }
 
 
-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 @@
 }
 
 uint32 Pixel::get() const {
+	assert(_vidMem >= _min);
+	assert(_vidMem <  _max);
+
 	if (_bpp == 1)
 		return *((byte *) _vidMem);
 	if (_bpp == 2)
@@ -86,6 +94,9 @@
 }
 
 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 @@
 }
 
 
-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 @@
 }
 
 uint32 ConstPixel::get() const {
+	assert(_vidMem >= _min);
+	assert(_vidMem <  _max);
+
 	if (_bpp == 1)
 		return *((const byte *) _vidMem);
 	if (_bpp == 2)
@@ -213,13 +232,13 @@
 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,

Modified: scummvm/trunk/engines/gob/surface.h
===================================================================
--- scummvm/trunk/engines/gob/surface.h	2011-01-27 19:20:27 UTC (rev 55570)
+++ scummvm/trunk/engines/gob/surface.h	2011-01-27 20:38:58 UTC (rev 55571)
@@ -35,7 +35,7 @@
 /** 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 @@
 
 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 @@
 
 private:
 	const byte *_vidMem;
+	const byte *_min, *_max;
 	uint8 _bpp;
 };
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list