Skip to content

Commit

Permalink
Update giflib to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
weareu authored and kant2002 committed Oct 2, 2015
1 parent f95b05c commit 8bd1b91
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 46 deletions.
23 changes: 18 additions & 5 deletions src/lib/gif/dgif_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ DGifOpenFileHandle(int FileHandle, int *Error)
/*@=mustfreeonly@*/

/* Let's see if this is a GIF file: */
/* coverity[check_return] */
if (READ(GifFile, (unsigned char *)Buf, GIF_STAMP_LEN) != GIF_STAMP_LEN) {
if (Error != NULL)
*Error = D_GIF_ERR_READ_FAILED;
Expand Down Expand Up @@ -188,6 +189,7 @@ DGifOpen(void *userData, InputFunc readFunc, int *Error)
GifFile->UserData = userData; /* TVT */

/* Lets see if this is a GIF file: */
/* coverity[check_return] */
if (READ(GifFile, (unsigned char *)Buf, GIF_STAMP_LEN) != GIF_STAMP_LEN) {
if (Error != NULL)
*Error = D_GIF_ERR_READ_FAILED;
Expand All @@ -209,7 +211,8 @@ DGifOpen(void *userData, InputFunc readFunc, int *Error)
if (DGifGetScreenDesc(GifFile) == GIF_ERROR) {
free((char *)Private);
free((char *)GifFile);
*Error = D_GIF_ERR_NO_SCRN_DSCR;
if (Error != NULL)
*Error = D_GIF_ERR_NO_SCRN_DSCR;
return NULL;
}

Expand Down Expand Up @@ -267,6 +270,7 @@ DGifGetScreenDesc(GifFileType *GifFile)
/* Get the global color map: */
GifFile->SColorMap->SortFlag = SortFlag;
for (i = 0; i < GifFile->SColorMap->ColorCount; i++) {
/* coverity[check_return] */
if (READ(GifFile, Buf, 3) != 3) {
GifFreeMapObject(GifFile->SColorMap);
GifFile->SColorMap = NULL;
Expand Down Expand Up @@ -299,6 +303,7 @@ DGifGetRecordType(GifFileType *GifFile, GifRecordType* Type)
return GIF_ERROR;
}

/* coverity[check_return] */
if (READ(GifFile, &Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR;
Expand Down Expand Up @@ -372,6 +377,7 @@ DGifGetImageDesc(GifFileType *GifFile)

/* Get the image local color map: */
for (i = 0; i < GifFile->Image.ColorMap->ColorCount; i++) {
/* coverity[check_return] */
if (READ(GifFile, Buf, 3) != 3) {
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Error = D_GIF_ERR_READ_FAILED;
Expand All @@ -385,12 +391,14 @@ DGifGetImageDesc(GifFileType *GifFile)
}

if (GifFile->SavedImages) {
if ((GifFile->SavedImages = (SavedImage *)realloc(GifFile->SavedImages,
sizeof(SavedImage) *
(GifFile->ImageCount + 1))) == NULL) {
SavedImage* new_saved_images =
(SavedImage *)realloc(GifFile->SavedImages,
sizeof(SavedImage) * (GifFile->ImageCount + 1));
if (new_saved_images == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
GifFile->SavedImages = new_saved_images;
} else {
if ((GifFile->SavedImages =
(SavedImage *) malloc(sizeof(SavedImage))) == NULL) {
Expand Down Expand Up @@ -519,6 +527,7 @@ DGifGetExtension(GifFileType *GifFile, int *ExtCode, GifByteType **Extension)
return GIF_ERROR;
}

/* coverity[check_return] */
if (READ(GifFile, &Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR;
Expand Down Expand Up @@ -546,7 +555,7 @@ DGifGetExtensionNext(GifFileType *GifFile, GifByteType ** Extension)
if (Buf > 0) {
*Extension = Private->Buf; /* Use private unused buffer. */
(*Extension)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */
/* coverity[tainted_data] */
/* coverity[tainted_data,check_return] */
if (READ(GifFile, &((*Extension)[1]), Buf) != Buf) {
GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR;
Expand Down Expand Up @@ -668,6 +677,7 @@ DGifGetWord(GifFileType *GifFile, GifWord *Word)
{
unsigned char c[2];

/* coverity[check_return] */
if (READ(GifFile, c, 2) != 2) {
GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR;
Expand Down Expand Up @@ -712,6 +722,7 @@ DGifGetCodeNext(GifFileType *GifFile, GifByteType **CodeBlock)
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;

/* coverity[tainted_data_argument] */
/* coverity[check_return] */
if (READ(GifFile, &Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR;
Expand Down Expand Up @@ -746,6 +757,7 @@ DGifSetupDecompress(GifFileType *GifFile)
GifPrefixType *Prefix;
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;

/* coverity[check_return] */
if (READ(GifFile, &CodeSize, 1) < 1) { /* Read Code size from file. */
return GIF_ERROR; /* Failed to read Code size. */
}
Expand Down Expand Up @@ -1021,6 +1033,7 @@ DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf, GifByteType *NextByte)
{
if (Buf[0] == 0) {
/* Needs to read the next buffer - this one is empty: */
/* coverity[check_return] */
if (READ(GifFile, Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR;
Expand Down
42 changes: 21 additions & 21 deletions src/lib/gif/egif_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ EGifOpenFileName(const char *FileName, const bool TestExistence, int *Error)
GifFileType *GifFile;

if (TestExistence)
FileHandle = open(FileName, O_WRONLY | O_CREAT | O_EXCL,
FileHandle = open(FileName, O_WRONLY | O_CREAT | O_EXCL,
S_IREAD | S_IWRITE);
else
FileHandle = open(FileName, O_WRONLY | O_CREAT | O_TRUNC,
FileHandle = open(FileName, O_WRONLY | O_CREAT | O_TRUNC,
S_IREAD | S_IWRITE);

if (FileHandle == -1) {
Expand Down Expand Up @@ -190,7 +190,7 @@ EGifGetGifVersion(GifFileType *GifFile)
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
int i, j;

/*
/*
* Bulletproofing - always write GIF89 if we need to.
* Note, we don't clear the gif89 flag here because
* users of the sequential API might have called EGifSetGifVersion()
Expand All @@ -217,7 +217,7 @@ EGifGetGifVersion(GifFileType *GifFile)
|| function == APPLICATION_EXT_FUNC_CODE)
Private->gif89 = true;
}

if (Private->gif89)
return GIF89_STAMP;
else
Expand All @@ -226,7 +226,7 @@ EGifGetGifVersion(GifFileType *GifFile)

/******************************************************************************
Set the GIF version. In the extremely unlikely event that there is ever
another version, replace the bool argument with an enum in which the
another version, replace the bool argument with an enum in which the
GIF87 value is 0 (numerically the same as bool false) and the GIF89 value
is 1 (numerically the same as bool true). That way we'll even preserve
object-file compatibility!
Expand All @@ -241,7 +241,7 @@ void EGifSetGifVersion(GifFileType *GifFile, const bool gif89)
/******************************************************************************
All writes to the GIF should go through this.
******************************************************************************/
static int InternalWrite(GifFileType *GifFileOut,
static int InternalWrite(GifFileType *GifFileOut,
const unsigned char *buf, size_t len)
{
GifFilePrivateType *Private = (GifFilePrivateType*)GifFileOut->Private;
Expand Down Expand Up @@ -561,7 +561,7 @@ EGifPutExtensionLeader(GifFileType *GifFile, const int ExtCode)
Put extension block data (see GIF manual) into a GIF file.
******************************************************************************/
int
EGifPutExtensionBlock(GifFileType *GifFile,
EGifPutExtensionBlock(GifFileType *GifFile,
const int ExtLen,
const void *Extension)
{
Expand Down Expand Up @@ -660,7 +660,7 @@ size_t EGifGCBToExtension(const GraphicsControlBlock *GCB,
Replace the Graphics Control Block for a saved image, if it exists.
******************************************************************************/

int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB,
int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB,
GifFileType *GifFile, int ImageIndex)
{
int i;
Expand Down Expand Up @@ -708,7 +708,7 @@ EGifPutCode(GifFileType *GifFile, int CodeSize, const GifByteType *CodeBlock)
}

/* No need to dump code size as Compression set up does any for us: */
/*
/*
* Buf = CodeSize;
* if (InternalWrite(GifFile, &Buf, 1) != 1) {
* GifFile->Error = E_GIF_ERR_WRITE_FAILED;
Expand Down Expand Up @@ -891,7 +891,7 @@ EGifCompressLine(GifFileType *GifFile,

while (i < LineLen) { /* Decode LineLen items. */
Pixel = Line[i++]; /* Get next pixel from stream. */
/* Form a new unique key to search hash table for the code combines
/* Form a new unique key to search hash table for the code combines
* CrntCode as Prefix string with Pixel as postfix char.
*/
NewKey = (((uint32_t) CrntCode) << 8) + Pixel;
Expand Down Expand Up @@ -1047,9 +1047,9 @@ EGifBufferedOutput(GifFileType *GifFile,
******************************************************************************/

static int
EGifWriteExtensions(GifFileType *GifFileOut,
ExtensionBlock *ExtensionBlocks,
int ExtensionBlockCount)
EGifWriteExtensions(GifFileType *GifFileOut,
ExtensionBlock *ExtensionBlocks,
int ExtensionBlockCount)
{
if (ExtensionBlocks) {
ExtensionBlock *ep;
Expand All @@ -1072,9 +1072,9 @@ EGifWriteExtensions(GifFileType *GifFileOut,
}

int
EGifSpew(GifFileType *GifFileOut)
EGifSpew(GifFileType *GifFileOut)
{
int i, j;
int i, j;

if (EGifPutScreenDesc(GifFileOut,
GifFileOut->SWidth,
Expand All @@ -1094,7 +1094,7 @@ EGifSpew(GifFileType *GifFileOut)
if (sp->RasterBits == NULL)
continue;

if (EGifWriteExtensions(GifFileOut,
if (EGifWriteExtensions(GifFileOut,
sp->ExtensionBlocks,
sp->ExtensionBlockCount) == GIF_ERROR)
return (GIF_ERROR);
Expand All @@ -1109,20 +1109,20 @@ EGifSpew(GifFileType *GifFileOut)
return (GIF_ERROR);

if (sp->ImageDesc.Interlace) {
/*
* The way an interlaced image should be written -
/*
* The way an interlaced image should be written -
* offsets and jumps...
*/
int InterlacedOffset[] = { 0, 4, 2, 1 };
int InterlacedJumps[] = { 8, 8, 4, 2 };
int k;
/* Need to perform 4 passes on the images: */
for (k = 0; k < 4; k++)
for (j = InterlacedOffset[k];
for (j = InterlacedOffset[k];
j < SavedHeight;
j += InterlacedJumps[k]) {
if (EGifPutLine(GifFileOut,
sp->RasterBits + j * SavedWidth,
if (EGifPutLine(GifFileOut,
sp->RasterBits + j * SavedWidth,
SavedWidth) == GIF_ERROR)
return (GIF_ERROR);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gif/gif_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" {

#define GIFLIB_MAJOR 5
#define GIFLIB_MINOR 1
#define GIFLIB_RELEASE 0
#define GIFLIB_RELEASE 1

#define GIF_ERROR 0
#define GIF_OK 1
Expand Down
Loading

0 comments on commit 8bd1b91

Please sign in to comment.