summaryrefslogtreecommitdiff
path: root/egif_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'egif_lib.c')
-rw-r--r--egif_lib.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/egif_lib.c b/egif_lib.c
index 4e353ba..3917ec6 100644
--- a/egif_lib.c
+++ b/egif_lib.c
@@ -105,6 +105,7 @@ EGifOpenFileHandle(const int FileHandle, int *Error)
*Error = E_GIF_ERR_NOT_ENOUGH_MEM;
return NULL;
}
+ /*@i1@*/memset(Private, '\0', sizeof(GifFilePrivateType));
if ((Private->HashTable = _InitHashTable()) == NULL) {
free(GifFile);
free(Private);
@@ -123,6 +124,7 @@ EGifOpenFileHandle(const int FileHandle, int *Error)
Private->FileHandle = FileHandle;
Private->File = f;
Private->FileState = FILE_STATE_WRITE;
+ Private->gif89 = false;
Private->Write = (OutputFunc) 0; /* No user write routine (MRB) */
GifFile->UserData = (void *)NULL; /* No user write handle (MRB) */
@@ -159,6 +161,8 @@ EGifOpen(void *userData, OutputFunc writeFunc, int *Error)
return NULL;
}
+ memset(Private, '\0', sizeof(GifFilePrivateType));
+
Private->HashTable = _InitHashTable();
if (Private->HashTable == NULL) {
free (GifFile);
@@ -186,7 +190,7 @@ EGifOpen(void *userData, OutputFunc writeFunc, int *Error)
/******************************************************************************
Routine to compute the GIF version that will be written on output.
******************************************************************************/
-char *
+const char *
EGifGetGifVersion(GifFileType *GifFile)
{
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
@@ -267,7 +271,7 @@ EGifPutScreenDesc(GifFileType *GifFile,
{
GifByteType Buf[3];
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
- char *write_version;
+ const char *write_version;
if (Private->FileState & FILE_STATE_SCREEN) {
/* If already has screen descriptor - something is wrong! */
@@ -379,6 +383,10 @@ EGifPutImageDesc(GifFileType *GifFile,
GifFile->Image.Height = Height;
GifFile->Image.Interlace = Interlace;
if (ColorMap) {
+ if (GifFile->Image.ColorMap != NULL) {
+ GifFreeMapObject(GifFile->Image.ColorMap);
+ GifFile->Image.ColorMap = NULL;
+ }
GifFile->Image.ColorMap = GifMakeMapObject(ColorMap->ColorCount,
ColorMap->Colors);
if (GifFile->Image.ColorMap == NULL) {
@@ -496,7 +504,7 @@ EGifPutPixel(GifFileType *GifFile, GifPixelType Pixel)
int
EGifPutComment(GifFileType *GifFile, const char *Comment)
{
- unsigned int length = strlen(Comment);
+ unsigned int length;
char *buf;
length = strlen(Comment);
@@ -750,7 +758,7 @@ EGifPutCodeNext(GifFileType *GifFile, const GifByteType *CodeBlock)
This routine should be called last, to close the GIF file.
******************************************************************************/
int
-EGifCloseFile(GifFileType *GifFile)
+EGifCloseFile(GifFileType *GifFile, int *ErrorCode)
{
GifByteType Buf;
GifFilePrivateType *Private;
@@ -764,7 +772,9 @@ EGifCloseFile(GifFileType *GifFile)
return GIF_ERROR;
if (!IS_WRITEABLE(Private)) {
/* This file was NOT open for writing: */
- GifFile->Error = E_GIF_ERR_NOT_WRITEABLE;
+ if (ErrorCode != NULL)
+ *ErrorCode = E_GIF_ERR_NOT_WRITEABLE;
+ free(GifFile);
return GIF_ERROR;
}
@@ -785,22 +795,19 @@ EGifCloseFile(GifFileType *GifFile)
if (Private->HashTable) {
free((char *) Private->HashTable);
}
- free((char *) Private);
+ free((char *) Private);
}
if (File && fclose(File) != 0) {
- GifFile->Error = E_GIF_ERR_CLOSE_FAILED;
+ if (ErrorCode != NULL)
+ *ErrorCode = E_GIF_ERR_CLOSE_FAILED;
+ free(GifFile);
return GIF_ERROR;
}
- /*
- * Without the #ifndef, we get spurious warnings because Coverity mistakenly
- * thinks the GIF structure is freed on an error return.
- */
-#ifndef __COVERITY__
free(GifFile);
-#endif /* __COVERITY__ */
-
+ if (ErrorCode != NULL)
+ *ErrorCode = E_GIF_SUCCEEDED;
return GIF_OK;
}
@@ -1140,7 +1147,7 @@ EGifSpew(GifFileType *GifFileOut)
GifFileOut->ExtensionBlockCount) == GIF_ERROR)
return (GIF_ERROR);
- if (EGifCloseFile(GifFileOut) == GIF_ERROR)
+ if (EGifCloseFile(GifFileOut, NULL) == GIF_ERROR)
return (GIF_ERROR);
return (GIF_OK);