#define PROGRAM_NAME "gif2rgb"
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "
for (i = 0; i < 3; i++) {
strncpy(OneFileName, FileName, sizeof(OneFileName)-1);
- /* cppcheck-suppress uninitstring */
strncat(OneFileName, Postfixes[i],
sizeof(OneFileName) - 1 - strlen(OneFileName));
}
fclose(rgbfp[0]);
- // cppcheck-suppress useClosedFile
fclose(rgbfp[1]);
- // cppcheck-suppress useClosedFile
fclose(rgbfp[2]);
}
}
Width, Height, ExpColorMapSize, 0,
OutputColorMap) == GIF_ERROR ||
EGifPutImageDesc(GifFile,
- 0, 0, Width, Height, false, NULL) ==
- GIF_ERROR)
+ 0, 0, Width, Height, false, NULL) == GIF_ERROR) {
PrintGifError(Error);
- if (GifFile != NULL) {
- EGifCloseFile(GifFile, NULL);
- }
exit(EXIT_FAILURE);
+ }
GifQprintf("\n%s: Image 1 at (%d, %d) [%dx%d]: ",
PROGRAM_NAME, GifFile->Image.Left, GifFile->Image.Top,
for (i = 0; i < Height; i++) {
if (EGifPutLine(GifFile, Ptr, Width) == GIF_ERROR)
- {
- if (GifFile != NULL) {
- EGifCloseFile(GifFile, NULL);
- }
exit(EXIT_FAILURE);
- }
GifQprintf("\b\b\b\b%-4d", Height - i - 1);
Ptr += Width;
}
- if (EGifCloseFile(GifFile, &Error) == GIF_ERROR)
+ if (EGifCloseFile(GifFile, &Error) == GIF_ERROR) {
PrintGifError(Error);
- if (GifFile != NULL) {
- EGifCloseFile(GifFile, NULL);
- }
exit(EXIT_FAILURE);
+ }
}
/******************************************************************************
for (i = 0; i < 3; i++) {
strncpy(OneFileName, FileName, sizeof(OneFileName)-1);
- /* cppcheck-suppress uninitstring */
strncat(OneFileName, Postfixes[i],
sizeof(OneFileName) - 1 - strlen(OneFileName));
rgbfp[0] = stdout;
}
+ if (ColorMap == NULL) {
+ fprintf(stderr, "Color map pointer is NULL.\n");
+ exit(EXIT_FAILURE);
+ }
+
if (OneFileFlag) {
unsigned char *Buffer, *BufferP;
free((char *) Buffers[1]);
free((char *) Buffers[2]);
fclose(rgbfp[0]);
- // cppcheck-suppress useClosedFile
fclose(rgbfp[1]);
- // cppcheck-suppress useClosedFile
fclose(rgbfp[2]);
}
}
}
}
+ if (GifFile->SHeight == 0 || GifFile->SWidth == 0) {
+ fprintf(stderr, "Image of width or height 0\n");
+ exit(EXIT_FAILURE);
+ }
+
/*
* Allocate the screen as vector of column of rows. Note this
* screen is device independent - it's the screen defined by the
break;
}
} while (RecordType != TERMINATE_RECORD_TYPE);
-
+
/* Lets dump it - set the global variables required and do it: */
ColorMap = (GifFile->Image.ColorMap
? GifFile->Image.ColorMap
#define DEFAULT_DIR "T" /* TOP (North) direction. */
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "
******************************************************************************/
int main(int argc, char **argv)
{
- unsigned int Ratio;
int i, l, LevelWidth, LogNumLevels, ErrorCode, Count = 0;
bool Error, FlipDir, DoAllMaximum = false,
DirectionFlag = false, LevelsFlag = false, ColorFlag = false,
break;
}
if (Direction == DIR_NONE)
- GIF_EXIT("Direction requested (-d option) is wierd!");
+ GIF_EXIT("Direction requested (-d option) is weird!");
/* We are going to handle only TOP, TOP_RIGHT, RIGHT, BOT_RIGHT so flip */
/* the complement cases (TOP <-> BOT for example) by flipping the */
for (i = 1; i <= NumLevels; i++) {
/* Ratio will be in the range of 0..100 for required intensity: */
- Ratio = (MaximumIntensity * (i * (256 / NumLevels)) +
- MinimumIntensity * ((NumLevels - i) * (256 / NumLevels))) /
- 256;
+ unsigned int Ratio = (MaximumIntensity * (i * (256 / NumLevels)) +
+ MinimumIntensity * ((NumLevels - i) * (256 / NumLevels))) /
+ 256;
ColorMap->Colors[i-1].Red = (RedColor * Ratio) / 100;
ColorMap->Colors[i-1].Green = (GreenColor * Ratio) / 100;
ColorMap->Colors[i-1].Blue = (BlueColor * Ratio) / 100;
if (EGifCloseFile(GifFile, &ErrorCode) == GIF_ERROR)
{
PrintGifError(ErrorCode);
- if (GifFile != NULL) {
- EGifCloseFile(GifFile, NULL);
- }
exit(EXIT_FAILURE);
}
#define PROGRAM_NAME "gifbuild"
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Eric Raymond, "
* 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);
#define PROGRAM_NAME "gifclrmp"
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "
/* pass through extension records */
if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
+ if (Extension == NULL)
+ break;
if (EGifPutExtensionLeader(GifFileOut, ExtCode) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (EGifPutExtensionBlock(GifFileOut,
#define LINE_LEN 40
#define IMAGEWIDTH LINE_LEN*GIF_FONT_WIDTH
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "
static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
int BufferWidth, int ForeGroundIndex)
{
- unsigned char c;
unsigned char Byte, Mask;
int i, j, k, CharPosX, Len = strlen(TextLine);
for (j = 0; j < GIF_FONT_HEIGHT; j++) RasterBuffer[j][i] = BackGround;
for (i = CharPosX = 0; i < Len; i++, CharPosX += GIF_FONT_WIDTH) {
- c = TextLine[i];
+ unsigned char c = TextLine[i];
for (j = 0; j < GIF_FONT_HEIGHT; j++) {
Byte = GifAsciiTable8x8[(unsigned short)c][j];
for (k = 0, Mask = 128; k < GIF_FONT_WIDTH; k++, Mask >>= 1)
#define DEFAULT_COLOR_GREEN 255
#define DEFAULT_COLOR_BLUE 255
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "
ForeGroundIndex = DEFAULT_FG_INDEX;
bool Error, ClrMapSizeFlag = false, ForeGroundFlag = false,
TextLineFlag = false, HelpFlag = false, ColorFlag = false;
- char *TextLines[MAX_NUM_TEXT_LINES], Line[LINE_LEN];
+ char *TextLines[MAX_NUM_TEXT_LINES];
GifRowType RasterBuffer[GIF_FONT_HEIGHT];
ColorMapObject *ColorMap;
GifFileType *GifFile;
ImageWidth = GIF_FONT_WIDTH * strlen(TextLines[0]);
}
else {
+ char Line[LINE_LEN];
NumOfLines = l = 0;
while (fgets(Line, LINE_LEN - 1, stdin)) {
for (i = strlen(Line); i > 0 && Line[i-1] <= ' '; i--);
if (EGifCloseFile(GifFile, &ErrorCode) == GIF_ERROR)
{
PrintGifError(ErrorCode);
- if (GifFile != NULL) {
- EGifCloseFile(GifFile, NULL);
- }
exit(EXIT_FAILURE);
}
static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
int BufferWidth, int ForeGroundIndex)
{
- unsigned char c;
unsigned char Byte, Mask;
int i, j, k, CharPosX, Len = strlen(TextLine);
for (j = 0; j < GIF_FONT_HEIGHT; j++) RasterBuffer[j][i] = 0;
for (i = CharPosX = 0; i < Len; i++, CharPosX += GIF_FONT_WIDTH) {
- c = TextLine[i];
+ unsigned char c = TextLine[i];
for (j = 0; j < GIF_FONT_HEIGHT; j++) {
Byte = GifAsciiTable8x8[(unsigned short)c][j];
for (k = 0, Mask = 128; k < GIF_FONT_WIDTH; k++, Mask >>= 1)
#define PROGRAM_NAME "giffix"
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "
******************************************************************************/
static void QuitGifError(GifFileType *GifFileIn, GifFileType *GifFileOut)
{
- fprintf(stderr, "\nFollowing unrecoverable error occured:");
+ fprintf(stderr, "\nFollowing unrecoverable error occurred:");
if (GifFileIn != NULL) {
PrintGifError(GifFileIn->Error);
EGifCloseFile(GifFileIn, NULL);
#define DEFAULT_HISTO_HEIGHT 256
#define HISTO_BITS_PER_PIXEL 2 /* Size of bitmap for histogram GIF. */
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "
*****************************************************************************/
- #include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <io.h>
+ #else
+ #include <unistd.h>
#endif /* _WIN32 */
#include "gif_lib.h"
#define DEFAULT_OUT_NAME "GifInto.Gif"
#define DEFAULT_TMP_NAME "TempInto.XXXXXX"
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "
int FD;
int NumFiles;
bool Error, MinSizeFlag = false, HelpFlag = false;
- char **FileName = NULL, FoutTmpName[STRLEN], FullPath[STRLEN], *p;
+ char **FileName = NULL, FoutTmpName[STRLEN+1], FullPath[STRLEN+1], *p;
FILE *Fin, *Fout;
if ((Error = GAGetArgs(argc, argv, CtrlStr, &GifNoisyPrint,
if ( *FileName == NULL ) GIF_EXIT("No valid Filename given.");
if ( strlen(*FileName) > STRLEN-1 ) GIF_EXIT("Filename too long.");
memset(FullPath, '\0', sizeof(FullPath));
- // cppcheck-suppress redundantCopy
strncpy(FullPath, *FileName, STRLEN);
if ((p = strrchr(FullPath, '/')) != NULL ||
(p = strrchr(FullPath, '\\')) != NULL)
fclose(Fout);
unlink(*FileName);
if (rename(FoutTmpName, *FileName) != 0) {
- char DefaultName[STRLEN];
+ char DefaultName[STRLEN+1];
+ memset(DefaultName, '\0', sizeof(DefaultName));
if ( (strlen(FullPath) + strlen(DEFAULT_OUT_NAME)) > STRLEN-1 ) GIF_EXIT("Filename too long.");
strncpy(DefaultName, FullPath, STRLEN);
- // cppcheck-suppress uninitstring
strcat(DefaultName, DEFAULT_OUT_NAME);
if (rename(FoutTmpName, DefaultName) == 0) {
char s[STRLEN];
#define MAKE_PRINTABLE(c) (isprint(c) ? (c) : ' ')
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "
{
static int CrntPlace = 0;
static long CodeCount = 0;
- int i, Percent, Len;
- long NumBytes;
+ int i, Len;
if (Reset || CodeBlock == NULL) {
if (CodeBlock == NULL) {
+ long NumBytes = 0;
if (CrntPlace > 0) {
printf("\n");
CodeCount += CrntPlace - 16;
if (GifFile->Image.ColorMap)
NumBytes = ((((long) GifFile->Image.Width) * GifFile->Image.Height)
* GifFile->Image.ColorMap->BitsPerPixel) / 8;
- else
+ else if (GifFile->SColorMap != NULL)
NumBytes = ((((long) GifFile->Image.Width) * GifFile->Image.Height)
* GifFile->SColorMap->BitsPerPixel) / 8;
- Percent = 100 * CodeCount / NumBytes;
- printf("\nCompression ratio: %ld/%ld (%d%%).\n",
+ /* FIXME: What should the compression ratio be if no color table? */
+ if (NumBytes > 0) {
+ int Percent = 100 * CodeCount / NumBytes;
+ printf("\nCompression ratio: %ld/%ld (%d%%).\n",
CodeCount, NumBytes, Percent);
+ }
return;
}
CrntPlace = 0;
#define DEFAULT_NUM_LEVELS 16 /* Number of colors to gen the image. */
+__attribute__((__section__(".tizen.build-id")))
static char
- *VersionStr =
+ VersionStr[] =
PROGRAM_NAME
VERSION_COOKIE
" Gershon Elber, "