From 5c4506a8c5ee1a82268146007619b09e980a7a57 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 2 May 2009 17:28:21 +0200 Subject: add some assert() to make tutor happy --- ue2/imgsynth2/cbitmap.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'ue2/imgsynth2/cbitmap.cpp') diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp index 3d206f5..3bff857 100644 --- a/ue2/imgsynth2/cbitmap.cpp +++ b/ue2/imgsynth2/cbitmap.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "cbitmap.h" using namespace std; @@ -28,7 +29,6 @@ CBitmap::~CBitmap() m_pixelformat = NULL; /* delete colortable content */ - //map::iterator it2; map::iterator it2; for(it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++) delete (*it2).second; @@ -67,6 +67,10 @@ void CBitmap::fillrect(std::list params) if (m_pixeldata == NULL || m_pixelformat == NULL) return; + assert(getHeight() > 0); + assert(getWidth() > 0); + assert(getPixelDataSize() > 0); + /* convert parameters */ uint32_t pparams[7]; int i = 0; @@ -106,7 +110,7 @@ void CBitmap::fillrect(std::list params) pixel.blue = pparams[6]; /* call setPixel for every pixel in the rectangel */ - /* NOTE: maybe use fill() here? */ + /* NOTE: maybe use std::fill() here? */ for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++) { for(uint32_t j = pparams[1]; j < pparams[3] + pparams[1]; j++) @@ -139,6 +143,10 @@ void CBitmap::invert(std::list params) if (m_pixeldata == NULL || m_pixelformat == NULL) return; + assert(getHeight() > 0); + assert(getWidth() > 0); + assert(getPixelDataSize() > 0); + CPixelFormat::RGBPIXEL pixel; CPixelFormat::RGBPIXEL max; m_pixelformat->getMaxColor(max); @@ -261,6 +269,11 @@ void CBitmap::mirror_y(std::list params) if (m_pixeldata == NULL || m_pixelformat == NULL) return; + assert(m_rowsize > 0); + assert(getHeight() > 0); + assert(getWidth() > 0); + assert(getPixelDataSize() > 0); + uint8_t *buf = new uint8_t[m_rowsize]; for(uint32_t i = 0; i < getHeight()/2; i++) { @@ -296,6 +309,11 @@ void CBitmap::mirror_x(std::list params) /* calc pixelwidth */ unsigned int pixelwidth = (hasColorTable()) ? sizeof(uint32_t) : m_pixelformat->getBitCount()/8; + assert(m_rowsize > 0); + assert(getHeight() > 0); + assert(getWidth() > 0); + assert(getPixelDataSize() > 0); + uint8_t *buf = new uint8_t[pixelwidth]; for(uint32_t i = 0; i < getHeight(); i++) { -- cgit v1.2.3