* Explicit header declarations
*/
- // cppcheck-suppress invalidscanf
if (sscanf(buf, "screen width %d\n", &GifFileOut->SWidth) == 1)
continue;
- // cppcheck-suppress invalidscanf
else if (sscanf(buf, "screen height %d\n", &GifFileOut->SHeight) == 1)
continue;
- // cppcheck-suppress invalidscanf
else if (sscanf(buf, "screen colors %d\n", &n) == 1)
{
int ResBits = GifBitSize(n);
continue;
}
- // cppcheck-suppress invalidscanf
else if (sscanf(buf,
"screen background %d\n",
&GifFileOut->SBackGroundColor) == 1)
continue;
- // cppcheck-suppress invalidscanf
else if (sscanf(buf, "pixel aspect byte %u\n", &intval) == 1) {
GifFileOut->AspectByte = (GifByteType)(intval & 0xff);
continue;
memset(LocalColorKeys, '\0', sizeof(LocalColorKeys));
}
- // cppcheck-suppress invalidscanf
else if (sscanf(buf, " rgb %d %d %d is %c",
&red, &green, &blue, &KeyTable[ColorMapSize]) == 4)
{
ColorMapSize++;
}
- // cppcheck-suppress invalidscanf
else if (sscanf(buf, " rgb %d %d %d", &red, &green, &blue) == 3)
{
ColorMap[ColorMapSize].Red = red;
}
/* GIF inclusion */
- // cppcheck-suppress invalidscanf
- else if (sscanf(buf, "include %s", InclusionFile) == 1)
+ /* ugly magic number is because scanf has no */
+ else if (sscanf(buf, "include %63s", InclusionFile) == 1)
{
int ErrorCode;
bool DoTranslation;
GifPixelType Translation[256];
GifFileType *Inclusion;
- SavedImage *NewImage, *CopyFrom;
+ SavedImage *CopyFrom;
if ((Inclusion = DGifOpenFileName(InclusionFile, &ErrorCode)) == NULL) {
PrintGifError(ErrorCode);
exit(EXIT_FAILURE);
}
+ //cppcheck-suppress nullPointerRedundantCheck
if ((DoTranslation = (GifFileOut->SColorMap!=(ColorMapObject*)NULL)))
{
ColorMapObject *UnionMap;
- UnionMap = GifUnionColorMap(GifFileOut->SColorMap,
- Inclusion->SColorMap, Translation);
+ //cppcheck-suppress nullPointerRedundantCheck
+ UnionMap = GifUnionColorMap(GifFileOut->SColorMap, Inclusion->SColorMap, Translation);
if (UnionMap == NULL)
{
PARSE_ERROR("Inclusion failed --- global map conflict.");
+ //cppcheck-suppress nullPointerRedundantCheck
PrintGifError(GifFileOut->Error);
if (Inclusion != NULL) DGifCloseFile(Inclusion, NULL);
if (GifFileOut != NULL) EGifCloseFile(GifFileOut, NULL);
GifFileOut->SColorMap = UnionMap;
}
+ //cppcheck-suppress nullPointerRedundantCheck
for (CopyFrom = Inclusion->SavedImages;
+ //cppcheck-suppress nullPointerRedundantCheck
CopyFrom < Inclusion->SavedImages + Inclusion->ImageCount;
CopyFrom++)
{
+ SavedImage *NewImage;
if ((NewImage = GifMakeSavedImage(GifFileOut, CopyFrom)) == NULL)
{
PARSE_ERROR("Inclusion failed --- out of memory.");
+ //cppcheck-suppress nullPointerRedundantCheck
PrintGifError(GifFileOut->Error);
if (Inclusion != NULL) DGifCloseFile(Inclusion, NULL);
if (GifFileOut != NULL) EGifCloseFile(GifFileOut, NULL);
while (isspace(*tp))
tp++;
- // cppcheck-suppress invalidscanf
if (sscanf(tp, "disposal mode %d\n", &gcb.DisposalMode))
continue;
if (strcmp(tp, "user input flag on\n") == 0) {
gcb.UserInputFlag = false;
continue;
}
- // cppcheck-suppress invalidscanf
if (sscanf(tp, "delay %d\n", &gcb.DelayTime))
continue;
- // cppcheck-suppress invalidscanf
if (sscanf(tp, "transparent index %d\n",
&gcb.TransparentColor))
continue;
}
}
- // cppcheck-suppress invalidscanf
else if (sscanf(buf, "netscape loop %u", &intval))
{
unsigned char params[3] = {1, 0, 0};
}
}
- // cppcheck-suppress invalidscanf
else if (sscanf(buf, "extension %x", &ExtCode))
{
int bc = 0;
/*
* Accept image attributes
*/
- // cppcheck-suppress invalidscanf
else if (sscanf(buf, "image top %d\n", &NewImage->ImageDesc.Top) == 1)
continue;
- // cppcheck-suppress invalidscanf
else if (sscanf(buf, "image left %d\n", &NewImage->ImageDesc.Left)== 1)
continue;
continue;
}
- // cppcheck-suppress invalidscanf
else if (sscanf(buf,
"image bits %d by %d",
&NewImage->ImageDesc.Width,
putchar('\n');
while (!last && ep[1].Function == CONTINUE_EXT_FUNC_CODE) {
++ep;
+ last = (ep - ExtensionBlocks == (ExtensionBlockCount - 1));
VisibleDumpBuffer(ep->Bytes, ep->ByteCount);
putchar('\n');
}
putchar('\n');
while (!last && ep[1].Function == CONTINUE_EXT_FUNC_CODE) {
++ep;
+ last = (ep - ExtensionBlocks == (ExtensionBlockCount - 1));
VisibleDumpBuffer(ep->Bytes, ep->ByteCount);
putchar('\n');
}
printf("\ttransparent index %d\n", gcb.TransparentColor);
printf("end\n\n");
}
- else if (ep->Function == APPLICATION_EXT_FUNC_CODE
+ else if (!last
+ && ep->Function == APPLICATION_EXT_FUNC_CODE
+ && ep->ByteCount >= 11
+ && (ep+1)->ByteCount >= 3
&& memcmp(ep->Bytes, "NETSCAPE2.0", 11) == 0) {
unsigned char *params = (++ep)->Bytes;
unsigned int loopcount = params[1] | (params[2] << 8);
VisibleDumpBuffer(ep->Bytes, ep->ByteCount);
while (!last && ep[1].Function == CONTINUE_EXT_FUNC_CODE) {
++ep;
+ last = (ep - ExtensionBlocks == (ExtensionBlockCount - 1));
VisibleDumpBuffer(ep->Bytes, ep->ByteCount);
putchar('\n');
}
for (i = 0; i < image->ImageDesc.Height; i++) {
for (j = 0; j < image->ImageDesc.Width; j++) {
GifByteType ch = image->RasterBits[i*image->ImageDesc.Width + j];
- if (ColorCount < PRINTABLES)
+ if (ColorCount < PRINTABLES && ch < PRINTABLES)
putchar(NameTable[ch]);
else
printf("%02x", ch);
if (fdin == -1)
(void) printf("# End of %s dump\n", FileName);
+
+ /*
+ * Sanity checks.
+ */
+
+ /* check that the background color isn't garbage (SF bug #87) */
+ if (GifFile->SBackGroundColor < 0
+ || GifFile->SBackGroundColor >= GifFile->SColorMap->ColorCount) {
+ fprintf(stderr, "gifbuild: background color invalid for screen colormap.\n");
+ }
+
if (DGifCloseFile(GifFile, &ErrorCode) == GIF_ERROR) {
PrintGifError(ErrorCode);
exit(EXIT_FAILURE);