From 0b269c601fca3163876b463baaa5a52cef8ccf26 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Thu, 28 Feb 2013 23:08:16 +0100 Subject: [PATCH] Fix #9487: GIFLoad array subscript below array bounds Recently enabled variable range propagation enables GCC to among others analyze whether array subscript is in a valid range. While being quite useful this particular feature also happens to produce false positives. This is merely a workaround to make compiler happy. The actual reason why compiler is reporting false positive is that array is indexed with a signed integer and it is not clear for compiler what value it may have due to it being a member of the class and and external procedure being invoked between its initialization and usage. --- src/add-ons/translators/gif/GIFLoad.cpp | 6 +++--- src/add-ons/translators/gif/GIFLoad.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/add-ons/translators/gif/GIFLoad.cpp b/src/add-ons/translators/gif/GIFLoad.cpp index 02a44f3e2d..64e73fef5e 100644 --- a/src/add-ons/translators/gif/GIFLoad.cpp +++ b/src/add-ons/translators/gif/GIFLoad.cpp @@ -339,7 +339,7 @@ GIFLoad::ReadGIFImageData() goto bad_end; //memcpy(newEntry, fOldCode, fOldCodeLength); - for (int x = 0; x < fOldCodeLength; x++) { + for (unsigned int x = 0; x < fOldCodeLength; x++) { newEntry[x] = fOldCode[x]; } @@ -347,7 +347,7 @@ GIFLoad::ReadGIFImageData() newEntry[fOldCodeLength] = *fTable[fNewCode]; } else { // Does not exist in table //memcpy(newEntry, fOldCode, fOldCodeLength); - for (int x = 0; x < fOldCodeLength; x++) { + for (unsigned int x = 0; x < fOldCodeLength; x++) { newEntry[x] = fOldCode[x]; } @@ -360,7 +360,7 @@ GIFLoad::ReadGIFImageData() fTable[fNextCode] = MemblockAllocate(fOldCodeLength + 1); //memcpy(fTable[fNextCode], newEntry, fOldCodeLength + 1); - for (int x = 0; x < fOldCodeLength + 1; x++) { + for (unsigned int x = 0; x < fOldCodeLength + 1; x++) { fTable[fNextCode][x] = newEntry[x]; } diff --git a/src/add-ons/translators/gif/GIFLoad.h b/src/add-ons/translators/gif/GIFLoad.h index 885364d835..a981b3f5b3 100644 --- a/src/add-ons/translators/gif/GIFLoad.h +++ b/src/add-ons/translators/gif/GIFLoad.h @@ -86,7 +86,7 @@ class GIFLoad { int fPass, fRow, fWidth, fHeight; unsigned char fOldCode[4096]; - int fOldCodeLength; + unsigned int fOldCodeLength; short fNewCode; int fBits, fMaxCode, fCodeSize; short fClearCode, fEndCode, fNextCode;