Re: [AD] compressing empty files

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> If `input' is an empty file, then:
> 
>     pack input packed ; pack u packed output
> 
> produces a one byte file.

Confirmed on 4.0.2 RC2.

> A tentative patch is attached.

--- src/file.c 10 Dec 2001 00:05:45 -0000 1.31
+++ src/file.c 26 Jun 2002 04:29:46 -0000
@@ -2153,8 +2153,10 @@
    f->buf_pos = f->buf;
    f->buf_size--;
    if (f->buf_size <= 0)
-      if (f->todo <= 0)
+      if (f->todo <= 0) {
   f->flags |= PACKFILE_FLAG_EOF;
+  return EOF;
+      }
 
    return *(f->buf_pos++);
 

There is the same pattern just above the refill_buffer function:

/* _sort_out_getc:
 *  Helper function for the pack_getc() macro.
 */
int _sort_out_getc(PACKFILE *f)
{
   if (f->buf_size == 0) {
      if (f->todo <= 0)
  f->flags |= PACKFILE_FLAG_EOF;
      return *(f->buf_pos++);
   }
   return refill_buffer(f);
}

Should it be corrected too ?

--
Eric Botcazou
ebotcazou@xxxxxxxxxx



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/