Imported Upstream version 5.1.9 into tizen
[platform/upstream/giflib.git] / gif2rgb.c
similarity index 96%
rename from util/gif2rgb.c
rename to gif2rgb.c
index 051c5a2..0269234 100644 (file)
+++ b/gif2rgb.c
@@ -96,7 +96,6 @@ static void LoadRGB(char *FileName,
 
            for (i = 0; i < 3; i++) {
                strncpy(OneFileName, FileName, sizeof(OneFileName)-1);
-               /* cppcheck-suppress uninitstring */
                strncat(OneFileName, Postfixes[i], 
                        sizeof(OneFileName) - 1 - strlen(OneFileName));
 
@@ -151,9 +150,7 @@ static void LoadRGB(char *FileName,
        }
 
        fclose(rgbfp[0]);
-       // cppcheck-suppress useClosedFile
        fclose(rgbfp[1]);
-       // cppcheck-suppress useClosedFile
        fclose(rgbfp[2]);
     }
 }
@@ -179,13 +176,10 @@ static void SaveGif(GifByteType *OutputBuffer,
                          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,
@@ -193,23 +187,16 @@ static void SaveGif(GifByteType *OutputBuffer,
 
     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);
+    }
 }
 
 /******************************************************************************
@@ -274,7 +261,6 @@ static void DumpScreen2RGB(char *FileName, int OneFileFlag,
 
             for (i = 0; i < 3; i++) {
                 strncpy(OneFileName, FileName, sizeof(OneFileName)-1);
-               /* cppcheck-suppress uninitstring */
                 strncat(OneFileName, Postfixes[i], 
                        sizeof(OneFileName) - 1 - strlen(OneFileName));
     
@@ -293,6 +279,11 @@ static void DumpScreen2RGB(char *FileName, int OneFileFlag,
         rgbfp[0] = stdout;
     }
 
+    if (ColorMap == NULL) {
+       fprintf(stderr, "Color map pointer is NULL.\n");
+       exit(EXIT_FAILURE);
+    }
+
     if (OneFileFlag) {
         unsigned char *Buffer, *BufferP;
 
@@ -340,9 +331,7 @@ static void DumpScreen2RGB(char *FileName, int OneFileFlag,
         free((char *) Buffers[1]);
         free((char *) Buffers[2]);
         fclose(rgbfp[0]);
-       // cppcheck-suppress useClosedFile
         fclose(rgbfp[1]);
-       // cppcheck-suppress useClosedFile
         fclose(rgbfp[2]);
     }
 }
@@ -379,6 +368,11 @@ static void GIF2RGB(int NumFiles, char *FileName,
        }
     }
 
+    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
@@ -468,7 +462,7 @@ static void GIF2RGB(int NumFiles, char *FileName,
                break;
        }
     } while (RecordType != TERMINATE_RECORD_TYPE);
-
+    
     /* Lets dump it - set the global variables required and do it: */
     ColorMap = (GifFile->Image.ColorMap
                ? GifFile->Image.ColorMap