]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/gifdecod.cpp
Spacing tweak
[wxWidgets.git] / src / common / gifdecod.cpp
index db8ac994df84931e58513134241eece23ed39480..9421dbd5be7828e32fd88c4cd15322c12dbcd447 100644 (file)
@@ -142,21 +142,18 @@ bool wxGIFDecoder::ConvertToImage(wxImage *image) const
         image->SetMask(false);
 
 #if wxUSE_PALETTE
-    if (pal)
-    {
-        unsigned char r[256];
-        unsigned char g[256];
-        unsigned char b[256];
-
-        for (i = 0; i < 256; i++)
-        {
-            r[i] = pal[3*i + 0];
-            g[i] = pal[3*i + 1];
-            b[i] = pal[3*i + 2];
-        }
+    unsigned char r[256];
+    unsigned char g[256];
+    unsigned char b[256];
 
-        image->SetPalette(wxPalette(256, r, g, b));
+    for (i = 0; i < 256; i++)
+    {
+        r[i] = pal[3*i + 0];
+        g[i] = pal[3*i + 1];
+        b[i] = pal[3*i + 2];
     }
+
+    image->SetPalette(wxPalette(256, r, g, b));
 #endif // wxUSE_PALETTE
 
     /* copy image data */
@@ -470,6 +467,25 @@ int wxGIFDecoder::dgif(GIFImage *img, int interl, int bits)
         /* make new entry in alphabet (only if NOT just cleared) */
         if (lastcode != -1)
         {
+            // Normally, after the alphabet is full and can't grow any
+            // further (ab_free == 4096), encoder should (must?) emit CLEAR
+            // to reset it. This checks whether we really got it, otherwise
+            // the GIF is damaged.
+            if (ab_free > ab_max)
+            {
+                delete[] ab_prefix;
+                delete[] ab_tail;
+                delete[] stack;
+                return wxGIF_INVFORMAT;
+            }
+
+            // This assert seems unnecessary since the condition above
+            // eliminates the only case in which it went false. But I really
+            // don't like being forced to ask "Who in .text could have
+            // written there?!" And I wouldn't have been forced to ask if
+            // this line had already been here.
+            wxASSERT(ab_free < allocSize);
+
             ab_prefix[ab_free] = lastcode;
             ab_tail[ab_free]   = code;
             ab_free++;