about summary refs log tree commit diff
path: root/converter/other/giftopnm.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-05-02 18:12:54 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-05-02 18:12:54 +0000
commit3fb9822420a65f1fa543e99edb55244ddf2a333a (patch)
treef2ed68d5e11ed3e16422950b76d93625ed780f3c /converter/other/giftopnm.c
parent16970c0de736133435e63a0efe43b860464199c4 (diff)
downloadnetpbm-mirror-3fb9822420a65f1fa543e99edb55244ddf2a333a.tar.gz
netpbm-mirror-3fb9822420a65f1fa543e99edb55244ddf2a333a.tar.xz
netpbm-mirror-3fb9822420a65f1fa543e99edb55244ddf2a333a.zip
Fix for block shorter than code
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@907 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/giftopnm.c')
-rw-r--r--converter/other/giftopnm.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/converter/other/giftopnm.c b/converter/other/giftopnm.c
index df049bf3..32023dce 100644
--- a/converter/other/giftopnm.c
+++ b/converter/other/giftopnm.c
@@ -75,7 +75,8 @@ readFile(FILE *          const ifP,
         else if (feof(ifP))
             asprintfN(errorP, "End of file encountered");
         else
-            asprintfN(errorP, "Short read -- %u bytes of %u", bytesRead, len);
+            asprintfN(errorP, "Short read -- %u bytes of %u",
+                              (unsigned)bytesRead, (unsigned)len);
     }
 }
 
@@ -582,16 +583,22 @@ getCode_get(struct getCodeState * const gsP,
   Return the code read (assuming *eofP == FALSE and *errorP == NULL)
   as *codeP.
 -----------------------------------------------------------------------------*/
-    if ((gsP->curbit+codeSize) > gsP->bufCount*8 && !gsP->streamExhausted) 
+
+    *errorP = NULL;
+
+    while (gsP->curbit + codeSize > gsP->bufCount * 8 &&
+           !gsP->streamExhausted && !*errorP) 
         /* Not enough left in buffer to satisfy request.  Get the next
            data block into the buffer.
+
+           Note that a data block may be as small as one byte, so we may need
+           to do this multiple times to get the full code.  (This probably
+           never happens in practice).
         */
         getAnotherBlock(ifP, gsP, errorP);
-    else
-        *errorP = NULL;
 
     if (!*errorP) {
-        if ((gsP->curbit+codeSize) > gsP->bufCount*8) {
+        if (gsP->curbit + codeSize > gsP->bufCount * 8) {
             /* The buffer still doesn't have enough bits in it; that means
                there were no data blocks left to read.
             */