From: Koji Arai Date: Thu, 5 Jun 2008 14:10:19 +0000 (+0900) Subject: should not change the value of the h->origsize X-Git-Url: http://git.osdn.net/view?p=lha%2Folha.git;a=commitdiff_plain;h=ac138e1157cb5bd9e7915972513239f00fd79445 should not change the value of the h->origsize --- diff --git a/ar.h b/ar.h index b9a5e64..b671538 100644 --- 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" diff --git a/extract.c b/extract.c index 22943b5..caa1b29 100644 --- 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; } }