OSDN Git Service

should not change the value of the h->origsize
authorKoji Arai <jca02266@gmail.com>
Thu, 5 Jun 2008 14:10:19 +0000 (23:10 +0900)
committerKoji Arai <jca02266@gmail.com>
Thu, 5 Jun 2008 14:10:19 +0000 (23:10 +0900)
ar.h
extract.c

diff --git a/ar.h b/ar.h
index b9a5e64..b671538 100644 (file)
--- a/ar.h
+++ b/ar.h
@@ -106,4 +106,7 @@ extern struct lha_opts opts;
 
 extern ushort left[], right[];
 
+/* utilities */
+#define MIN(a, b) (((a) > (b)) ? (b) : (a))
+
 #include "prototypes.h"
index 22943b5..caa1b29 100644 (file)
--- a/extract.c
+++ b/extract.c
@@ -8,7 +8,6 @@
 void
 extract(struct lzh_istream *rp, int to_file, struct lzh_header *h)
 {
-    int n;
     FILE *outfile = NULL;
     unsigned int crc;
 
@@ -57,12 +56,13 @@ extract(struct lzh_istream *rp, int to_file, struct lzh_header *h)
         char buf[MAXDICSIZ];
         unsigned int slide_off = 0;
         int slide_len = 0;
+        unsigned long remainder = h->origsize;
 
         crc = INIT_CRC;
         if (opts.method->dicbit != 0)
             decode_start(rp);
-        while (h->origsize != 0) {
-            n = (uint) ((h->origsize > MAXDICSIZ) ? MAXDICSIZ : h->origsize);
+        while (remainder != 0) {
+            uint n = (uint)MIN(remainder, MAXDICSIZ);
             if (opts.method->dicbit != 0)
                 decode(rp, n, buf, &slide_off, &slide_len);
             else {
@@ -74,7 +74,7 @@ extract(struct lzh_istream *rp, int to_file, struct lzh_header *h)
             if (outfile != stdout && opts.quiet < 1) {
                 putc('.', stdout);
             }
-            h->origsize -= n;
+            remainder -= n;
         }
     }