From d95e3e00557732ef6d000f8870fe9590b5ca441c Mon Sep 17 00:00:00 2001 From: mfranz Date: Sat, 28 Apr 2007 23:13:13 +0000 Subject: [PATCH] don't rely on a compressed scanline being properly closed (GIMP apparently generates corrupted files) --- simgear/screen/texture.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/simgear/screen/texture.cxx b/simgear/screen/texture.cxx index 8fede149..fd4aaf89 100644 --- a/simgear/screen/texture.cxx +++ b/simgear/screen/texture.cxx @@ -670,12 +670,12 @@ SGTexture::ImageGetRow(SGTexture::ImageRec *image, GLubyte *buf, int y, int z) { if ((image->type & 0xFF00) == 0x0100) { gzseek(image->file, (long) image->rowStart[y+z*image->ysize], SEEK_SET); - gzread(image->file, image->tmp, - (unsigned int)image->rowSize[y+z*image->ysize]); + int size = image->rowSize[y+z*image->ysize]; + gzread(image->file, image->tmp, size); iPtr = image->tmp; oPtr = buf; - for (;;) { + for (GLubyte *limit = iPtr + size; iPtr < limit;) { pixel = *iPtr++; count = (int)(pixel & 0x7F); if (!count) { @@ -683,10 +683,10 @@ SGTexture::ImageGetRow(SGTexture::ImageRec *image, GLubyte *buf, int y, int z) { return; } if (pixel & 0x80) { - while (count--) { + while (iPtr < limit && count--) { *oPtr++ = *iPtr++; } - } else { + } else if (iPtr < limit) { pixel = *iPtr++; while (count--) { *oPtr++ = pixel; -- 2.39.5