From a538dd33b70b097a86950e78df43fd3c5bd60cdd Mon Sep 17 00:00:00 2001
From: Pawel Dziepak <pdziepak@quarnos.org>
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 02a44f3..64e73fe 100644
a
|
b
|
GIFLoad::ReadGIFImageData()
|
339 | 339 | goto bad_end; |
340 | 340 | |
341 | 341 | //memcpy(newEntry, fOldCode, fOldCodeLength); |
342 | | for (int x = 0; x < fOldCodeLength; x++) { |
| 342 | for (unsigned int x = 0; x < fOldCodeLength; x++) { |
343 | 343 | newEntry[x] = fOldCode[x]; |
344 | 344 | } |
345 | 345 | |
… |
… |
GIFLoad::ReadGIFImageData()
|
347 | 347 | newEntry[fOldCodeLength] = *fTable[fNewCode]; |
348 | 348 | } else { // Does not exist in table |
349 | 349 | //memcpy(newEntry, fOldCode, fOldCodeLength); |
350 | | for (int x = 0; x < fOldCodeLength; x++) { |
| 350 | for (unsigned int x = 0; x < fOldCodeLength; x++) { |
351 | 351 | newEntry[x] = fOldCode[x]; |
352 | 352 | } |
353 | 353 | |
… |
… |
GIFLoad::ReadGIFImageData()
|
360 | 360 | fTable[fNextCode] = MemblockAllocate(fOldCodeLength + 1); |
361 | 361 | |
362 | 362 | //memcpy(fTable[fNextCode], newEntry, fOldCodeLength + 1); |
363 | | for (int x = 0; x < fOldCodeLength + 1; x++) { |
| 363 | for (unsigned int x = 0; x < fOldCodeLength + 1; x++) { |
364 | 364 | fTable[fNextCode][x] = newEntry[x]; |
365 | 365 | } |
366 | 366 | |
diff --git a/src/add-ons/translators/gif/GIFLoad.h b/src/add-ons/translators/gif/GIFLoad.h
index 885364d..a981b3f 100644
a
|
b
|
class GIFLoad {
|
86 | 86 | int fPass, fRow, fWidth, fHeight; |
87 | 87 | |
88 | 88 | unsigned char fOldCode[4096]; |
89 | | int fOldCodeLength; |
| 89 | unsigned int fOldCodeLength; |
90 | 90 | short fNewCode; |
91 | 91 | int fBits, fMaxCode, fCodeSize; |
92 | 92 | short fClearCode, fEndCode, fNextCode; |