Eric-- How about the attached? It combines the previous minimal fix, and I think updates all the call sites for CRC routines.
--Joe On Mon, Jan 12, 2026 at 11:22 PM Joseph Oswald <[email protected]> wrote: > Thanks for looking it over. > > Fair enough, my initial patch was deliberately intended to be minimal, but > if you would prefer my updating the uses of the libraries I can do that, > although the changes will touch several more files. > > I think I have it working on my local git repo, it will take me a bit for > me to convert it into the patch format. > > --Joe > > On Sun, Jan 4, 2026 at 1:48 PM Eric Sharkey <[email protected]> wrote: > >> Finally getting around to looking at this. The patch includes this bit: >> >> +- (void)fprintf(fd, "unsigned long %s_crcinit = %d;\n", name, init); >> ++ (void)fprintf(fd, "#include <stdint.h>\n\n"); >> ++ if (bits == 16) { >> ++ (void)fprintf(fd, "uint16_t %s_crcinit = %d;\n", name, init); >> ++ } else { >> ++ (void)fprintf(fd, "uint32_t %s_crcinit = %d;\n", name, init); >> ++ } >> >> Which changes the number of bits in the initial value, but this initial >> value is used to initialize the global element defined in crc.c as: >> >> unsigned long crcinit; >> >> e.g., in macunpack/cpt.c: >> >> crcinit = zip_crcinit; >> >> and macunpack/crc.h still declares these as: >> >> extern unsigned long arc_crcinit; >> extern unsigned long binhex_crcinit; >> extern unsigned long zip_crcinit; >> >> which isn't modified by your patch, so the headers get out of sync with >> the actual code generated by makecrc. It probably works in practice, but >> this should be cleaned up before being uploaded. >> >> Eric >> >>>
From: "Joseph A. Oswald, III" <[email protected]> Date: Tue, 13 Jan 2026 20:48:15 -0500 Subject: * crc/makecrc.c: use explictly sized uint16|32_t types. Includes updates to all call-sites Closes: #1123798 (LP: #2136046) --- binhex/dofile.c | 9 +++++---- crc/makecrc.c | 28 ++++++++++++++++++++-------- hexbin/crc.c | 8 ++++---- hexbin/crc.h | 8 +++++--- hexbin/hecx.c | 6 +++--- hexbin/hqx.c | 6 +++--- macunpack/arc.h | 4 +++- macunpack/cpt.c | 32 ++++++++++++++++---------------- macunpack/cpt.h | 6 ++++-- macunpack/crc.c | 7 +++++-- macunpack/crc.h | 22 +++++++++++++--------- macunpack/dd.c | 56 +++++++++++++++++++++++++++++--------------------------- macunpack/lzh.c | 4 ++-- macunpack/pit.c | 8 ++++---- macunpack/pit.h | 4 +++- macunpack/sit.c | 10 +++++----- macunpack/sit.h | 8 +++++--- macunpack/zma.c | 4 ++-- macunpack/zma.h | 5 +++-- 19 files changed, 134 insertions(+), 101 deletions(-) diff --git a/binhex/dofile.c b/binhex/dofile.c index 6ecb522..baa1711 100755 --- a/binhex/dofile.c +++ b/binhex/dofile.c @@ -1,3 +1,4 @@ +#include <stdint.h> #include<stdio.h> #include<stdlib.h> #include<unistd.h> @@ -5,8 +6,8 @@ #include "../fileio/rdfile.h" extern int dorep; -extern unsigned long binhex_crcinit; -extern unsigned long binhex_updcrc(); +extern uint16_t binhex_crcinit; +extern uint16_t binhex_updcrc(); #define RUNCHAR 0x90 @@ -45,7 +46,7 @@ void dofile() void doheader() { -unsigned long crc; +uint16_t crc; int i, n; crc = binhex_crcinit; @@ -85,7 +86,7 @@ void dofork(fork, size) char *fork; int size; { -unsigned long crc; +uint16_t crc; int i; crc = binhex_updcrc(binhex_crcinit, fork, size); diff --git a/crc/makecrc.c b/crc/makecrc.c index f4621bb..eecbef1 100755 --- a/crc/makecrc.c +++ b/crc/makecrc.c @@ -34,6 +34,7 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> +#include <stdint.h> static void initcrctab(); @@ -54,8 +55,8 @@ char *name; int poly, init, swapped, bits; { register int b, i; - unsigned short v; - unsigned long vv; + uint16_t v; + uint32_t vv; FILE *fd; char buf[20]; @@ -66,12 +67,17 @@ int poly, init, swapped, bits; (void)fprintf(stderr, "Cannot open %s for writing\n", buf); exit(1); } - (void)fprintf(fd, "unsigned long %s_crcinit = %d;\n", name, init); + (void)fprintf(fd, "#include <stdint.h>\n\n"); + if (bits == 16) { + (void)fprintf(fd, "uint16_t %s_crcinit = %d;\n", name, init); + } else { + (void)fprintf(fd, "uint32_t %s_crcinit = %d;\n", name, init); + } (void)fprintf(fd, "\n"); if(bits == 16) { - (void)fprintf(fd, "static unsigned short crctab[256] = {\n"); + (void)fprintf(fd, "static uint16_t crctab[256] = {\n"); } else { - (void)fprintf(fd, "static unsigned long crctab[256] = {\n"); + (void)fprintf(fd, "static uint32_t crctab[256] = {\n"); } (void)fprintf(fd, " "); if(bits == 16) { @@ -111,19 +117,25 @@ int poly, init, swapped, bits; } (void)fprintf(fd, "};\n"); (void)fprintf(fd, "\n"); - (void)fprintf(fd, "unsigned long %s_updcrc(icrc, icp, icnt)\n", name); - (void)fprintf(fd, " unsigned long icrc;\n"); + if (bits == 16) { + (void)fprintf(fd, "uint16_t %s_updcrc(icrc, icp, icnt)\n", name); + (void)fprintf(fd, " uint16_t icrc;\n"); + } else { + (void)fprintf(fd, "uint32_t %s_updcrc(icrc, icp, icnt)\n", name); + (void)fprintf(fd, " uint32_t icrc;\n"); + } (void)fprintf(fd, " unsigned char *icp;\n"); (void)fprintf(fd, " int icnt;\n"); (void)fprintf(fd, "{\n"); if(bits == 16) { (void)fprintf(fd, "#define M1 0xff\n"); (void)fprintf(fd, "#define M2 0xff00\n"); + (void)fprintf(fd, " register uint16_t crc = icrc;\n"); } else { (void)fprintf(fd, "#define M1 0xffffff\n"); (void)fprintf(fd, "#define M2 0xffffff00\n"); + (void)fprintf(fd, " register uint32_t crc = icrc;\n"); } - (void)fprintf(fd, " register unsigned long crc = icrc;\n"); (void)fprintf(fd, " register unsigned char *cp = icp;\n"); (void)fprintf(fd, " register int cnt = icnt;\n"); (void)fprintf(fd, "\n"); diff --git a/hexbin/crc.c b/hexbin/crc.c index e5e59c0..ac8e032 100755 --- a/hexbin/crc.c +++ b/hexbin/crc.c @@ -8,11 +8,11 @@ extern void exit(); -unsigned long crc; +uint16_t crc; #ifdef HQX void comp_q_crc(c) -register unsigned int c; +register uint16_t c; { unsigned char cc = c; @@ -27,13 +27,13 @@ register unsigned char *s, *e; #endif /* HQX */ void verify_crc(calc_crc, file_crc) -unsigned long calc_crc, file_crc; +uint16_t calc_crc, file_crc; { calc_crc &= WORDMASK; file_crc &= WORDMASK; if(calc_crc != file_crc) { - (void)fprintf(stderr, "CRC mismatch: got 0x%04lx, need 0x%04lx\n", + (void)fprintf(stderr, "CRC mismatch: got 0x%04x, need 0x%04x\n", file_crc, calc_crc); #ifdef SCAN do_error("hexbin: CRC error"); diff --git a/hexbin/crc.h b/hexbin/crc.h index 67e49fb..10c4ac5 100755 --- a/hexbin/crc.h +++ b/hexbin/crc.h @@ -1,8 +1,10 @@ +#include <stdint.h> + #define INITCRC binhex_crcinit -extern unsigned long crc; -extern unsigned long binhex_crcinit; -extern unsigned long binhex_updcrc(); +extern uint16_t crc; +extern uint16_t binhex_crcinit; +extern uint16_t binhex_updcrc(); extern void comp_q_crc(); extern void comp_q_crc_n(); diff --git a/hexbin/hecx.c b/hexbin/hecx.c index 5d19d8e..f87709e 100755 --- a/hexbin/hecx.c +++ b/hexbin/hecx.c @@ -98,7 +98,7 @@ char *macname, *filename; static void do_o_forks() { int forks = 0, found_crc = 0; - unsigned long calc_crc, file_crc; + uint16_t calc_crc, file_crc; crc = 0; /* calculate a crc for both forks */ @@ -127,13 +127,13 @@ static void do_o_forks() if(compressed && strncmp(line, "***CRC:", 7) == 0) { found_crc++; calc_crc = crc; - (void)sscanf(&line[7], "%lx", &file_crc); + (void)sscanf(&line[7], "%hx", &file_crc); break; } if(!compressed && strncmp(line, "***CHECKSUM:", 12) == 0) { found_crc++; calc_crc = crc & BYTEMASK; - (void)sscanf(&line[12], "%lx", &file_crc); + (void)sscanf(&line[12], "%hx", &file_crc); file_crc &= BYTEMASK; break; } diff --git a/hexbin/hqx.c b/hexbin/hqx.c index 0006091..94ada8a 100755 --- a/hexbin/hqx.c +++ b/hexbin/hqx.c @@ -98,8 +98,8 @@ static unsigned char *oq; static int ostate = S_HEADER; -static unsigned long calc_crc; -static unsigned long file_crc; +static uint16_t calc_crc; +static uint16_t file_crc; static long todo; @@ -235,7 +235,7 @@ done: static void get_header() { int n; - unsigned long calc_crc, file_crc; + uint16_t calc_crc, file_crc; crc = INITCRC; /* compute a crc for the header */ diff --git a/macunpack/arc.h b/macunpack/arc.h index 59c7f8e..ff284ed 100755 --- a/macunpack/arc.h +++ b/macunpack/arc.h @@ -1,3 +1,5 @@ +#include <stdint.h> + #define MAGIC1 0 /* Should be 0x1b, marks Mac extension */ #define KIND 1 /* KIND == 0 marks end of archive */ #define FNAME 2 @@ -35,7 +37,7 @@ typedef struct fileHdr { /* 84 or 88 bytes */ unsigned long size; unsigned short date; unsigned short time; - unsigend short crc; + uint16_t crc; unsigned long size2; /* Identical to size; this is wrong for Arc! */ }; diff --git a/macunpack/cpt.c b/macunpack/cpt.c index 8b2b81c..797c80a 100755 --- a/macunpack/cpt.c +++ b/macunpack/cpt.c @@ -29,7 +29,7 @@ static unsigned long cpt_datasize; static unsigned char cpt_LZbuff[CIRCSIZE]; static unsigned int cpt_LZptr; static unsigned char *cpt_char; -static unsigned long cpt_crc; +static uint32_t cpt_crc; static unsigned long cpt_inlength; static unsigned long cpt_outlength; static int cpt_outstat; @@ -64,9 +64,9 @@ void cpt() char *cptptr; int i; - updcrc = zip_updcrc; - crcinit = zip_crcinit; - cpt_crc = INIT_CRC; + updcrc_32 = zip_updcrc; + crcinit_32 = zip_crcinit; + cpt_crc = INIT_CRC_32; if(readcpthdr(&cpthdr) == 0) { (void)fprintf(stderr, "Can't read archive header\n"); #ifdef SCAN @@ -92,11 +92,11 @@ void cpt() #endif /* SCAN */ exit(1); } - cpt_crc = (*updcrc)(cpt_crc, cptptr, cpthdr.commentsize); + cpt_crc = (*updcrc_32)(cpt_crc, cptptr, cpthdr.commentsize); for(i = 0; i < cpthdr.entries; i++) { *cptptr = getc(infp); - cpt_crc = (*updcrc)(cpt_crc, cptptr, 1); + cpt_crc = (*updcrc_32)(cpt_crc, cptptr, 1); if(*cptptr & 0x80) { cptptr[F_FOLDER] = 1; *cptptr &= 0x3f; @@ -110,7 +110,7 @@ void cpt() #endif /* SCAN */ exit(1); } - cpt_crc = (*updcrc)(cpt_crc, cptptr + 1, *cptptr); + cpt_crc = (*updcrc_32)(cpt_crc, cptptr + 1, *cptptr); if(cptptr[F_FOLDER]) { if(fread(cptptr + F_FOLDERSIZE, 1, 2, infp) != 2) { (void)fprintf(stderr, "Can't read file header #%d\n", i+1); @@ -119,7 +119,7 @@ void cpt() #endif /* SCAN */ exit(1); } - cpt_crc = (*updcrc)(cpt_crc, cptptr + F_FOLDERSIZE, 2); + cpt_crc = (*updcrc_32)(cpt_crc, cptptr + F_FOLDERSIZE, 2); } else { if(fread(cptptr + F_VOLUME, 1, FILEHDRSIZE - F_VOLUME, infp) != FILEHDRSIZE - F_VOLUME) { @@ -129,14 +129,14 @@ void cpt() #endif /* SCAN */ exit(1); } - cpt_crc = (*updcrc)(cpt_crc, cptptr + F_VOLUME, - FILEHDRSIZE - F_VOLUME); + cpt_crc = (*updcrc_32)(cpt_crc, cptptr + F_VOLUME, + FILEHDRSIZE - F_VOLUME); } cptptr += FILEHDRSIZE; } if(cpt_crc != cpthdr.hdrcrc) { (void)fprintf(stderr, "Header CRC mismatch: got 0x%08x, need 0x%08x\n", - (int)cpthdr.hdrcrc, (int)cpt_crc); + (uint32_t)cpthdr.hdrcrc, (uint32_t)cpt_crc); #ifdef SCAN do_error("macunpack: Header CRC mismatch"); #endif /* SCAN */ @@ -203,7 +203,7 @@ struct cptHdr *s; return 0; } - cpt_crc = (*updcrc)(cpt_crc, temp + CPTHDRSIZE + C_ENTRIES, 3); + cpt_crc = (*updcrc_32)(cpt_crc, temp + CPTHDRSIZE + C_ENTRIES, 3); s->hdrcrc = get4(temp + CPTHDRSIZE + C_HDRCRC); s->entries = get2(temp + CPTHDRSIZE + C_ENTRIES); s->commentsize = temp[CPTHDRSIZE + C_COMMENT]; @@ -345,7 +345,7 @@ struct fileHdr filehdr; } if(write_it) { start_info(info, filehdr.rsrcLength, filehdr.dataLength); - cpt_crc = INIT_CRC; + cpt_crc = INIT_CRC_32; cpt_char = cpt_data + filehdr.filepos; } if(verbose) { @@ -384,8 +384,8 @@ struct fileHdr filehdr; filehdr.cptFlag & 4); if(filehdr.fileCRC != cpt_crc) { (void)fprintf(stderr, - "CRC error on file: need 0x%08lx, got 0x%08lx\n", - (long)filehdr.fileCRC, (long)cpt_crc); + "CRC error on file: need 0x%08x, got 0x%08x\n", + (uint32_t)filehdr.fileCRC, (uint32_t)cpt_crc); #ifdef SCAN do_error("macunpack: CRC error on file"); #endif /* SCAN */ @@ -415,7 +415,7 @@ unsigned short type; } else { cpt_rle_lzh(); } - cpt_crc = (*updcrc)(cpt_crc, out_buffer, obytes); + cpt_crc = (*updcrc_32)(cpt_crc, out_buffer, obytes); } void cpt_wrfile1(in_char, ibytes, obytes, type, blocksize) diff --git a/macunpack/cpt.h b/macunpack/cpt.h index 22637d3..55f4638 100755 --- a/macunpack/cpt.h +++ b/macunpack/cpt.h @@ -1,3 +1,5 @@ +#include <stdint.h> + #define C_SIGNATURE 0 #define C_VOLUME 1 #define C_XMAGIC 2 @@ -37,7 +39,7 @@ struct cptHdr { /* 8 bytes */ unsigned short xmagic; /* verification multi-file consistency*/ unsigned long offset; /* index offset */ /* The following are really in header2 at offset */ - unsigned long hdrcrc; /* header crc */ + uint32_t hdrcrc; /* header crc */ unsigned short entries; /* number of index entries */ unsigned char commentsize; /* number of bytes comment that follow*/ }; @@ -55,7 +57,7 @@ struct fileHdr { /* 78 bytes */ unsigned short FndrFlags; /* copy of Finder flags. For our purposes, we can clear: busy,onDesk */ - unsigned long fileCRC; /* crc on file */ + uint32_t fileCRC; /* crc on file */ unsigned short cptFlag; /* cpt flags */ unsigned long rsrcLength; /* decompressed lengths */ unsigned long dataLength; diff --git a/macunpack/crc.c b/macunpack/crc.c index 0e0baf3..8a4cb03 100755 --- a/macunpack/crc.c +++ b/macunpack/crc.c @@ -1,4 +1,7 @@ -unsigned long crcinit; +#include <stdint.h> -unsigned long (*updcrc)(); +uint16_t crcinit; +uint32_t crcinit_32; +uint16_t (*updcrc)(); +uint32_t (*updcrc_32)(); diff --git a/macunpack/crc.h b/macunpack/crc.h index b339d36..d3cfbbb 100755 --- a/macunpack/crc.h +++ b/macunpack/crc.h @@ -1,13 +1,17 @@ -#define INIT_CRC crcinit +#include <stdint.h> -extern unsigned long arc_crcinit; -extern unsigned long binhex_crcinit; -extern unsigned long zip_crcinit; +#define INIT_CRC crcinit +#define INIT_CRC_32 crcinit_32 -extern unsigned long arc_updcrc(); -extern unsigned long binhex_updcrc(); -extern unsigned long zip_updcrc(); +extern uint16_t arc_crcinit; +extern uint16_t binhex_crcinit; +extern uint32_t zip_crcinit; -extern unsigned long crcinit; -extern unsigned long (*updcrc)(); +extern uint16_t arc_updcrc(); +extern uint16_t binhex_updcrc(); +extern uint32_t zip_updcrc(); +extern uint16_t crcinit; +extern uint16_t (*updcrc)(); +extern uint32_t crcinit_32; +extern uint32_t (*updcrc_32)(); diff --git a/macunpack/dd.c b/macunpack/dd.c index 2c2377f..c2c2c86 100755 --- a/macunpack/dd.c +++ b/macunpack/dd.c @@ -21,9 +21,9 @@ static void dd_cfilehdr(); static int dd_valid(); static int dd_valid1(); static char *dd_methname(); -static unsigned long dd_checksum(); +static uint16_t dd_checksum(); static void dd_chksum(); -static unsigned long dd_checkor(); +static uint16_t dd_checkor(); static void dd_do_delta(); static void dd_delta(); static void dd_delta3(); @@ -151,7 +151,7 @@ void dd_arch(bin_hdr) unsigned char *bin_hdr; { unsigned long data_size; - unsigned long crc, filecrc; + uint16_t crc, filecrc; struct fileHdr f; struct fileCHdr cf; char locname[64]; @@ -212,7 +212,7 @@ unsigned char *bin_hdr; filecrc = get2((char *)dd_archive + ARCHHDRCRC); if(crc != filecrc) { (void)fprintf(stderr, "Header CRC mismatch: got 0x%02x, need 0x%02x\n", - (int)crc, (int)filecrc); + (uint16_t)crc, (uint16_t)filecrc); #ifdef SCAN do_error("macunpack: Header CRC mismatch"); #endif /* SCAN */ @@ -322,7 +322,7 @@ struct fileCHdr *cf; int skip; { register int i; - unsigned long crc; + uint16_t crc; int n, to_uncompress; unsigned char *hdr; char ftype[5], fauth[5]; @@ -340,7 +340,7 @@ int skip; f->hdrcrc = get2((char *)hdr + D_HDRCRC); if(f->hdrcrc != crc) { (void)fprintf(stderr, "Header CRC mismatch: got 0x%04x, need 0x%04x\n", - f->hdrcrc & WORDMASK, (int)crc); + f->hdrcrc & WORDMASK, (uint16_t)crc); #ifdef SCAN do_error("macunpack: Header CRC mismatch"); #endif /* SCAN */ @@ -428,7 +428,7 @@ int skip; static void dd_cfilehdr(f) struct fileCHdr *f; { - unsigned long crc; + uint16_t crc; unsigned char *hdr; hdr = dd_data_ptr; @@ -439,7 +439,7 @@ struct fileCHdr *f; f->hdrcrc = get2((char *)hdr + C_HDRCRC); if(f->hdrcrc != crc) { (void)fprintf(stderr, "Header CRC mismatch: got 0x%04x, need 0x%04x\n", - f->hdrcrc & WORDMASK, (int)crc); + f->hdrcrc & WORDMASK, (uint16_t)crc); #ifdef SCAN do_error("macunpack: Header CRC mismatch"); #endif /* SCAN */ @@ -512,13 +512,13 @@ int i, nmeths; return NULL; } -static unsigned long dd_checksum(init, buffer, length) -unsigned long init; +static uint16_t dd_checksum(init, buffer, length) +uint16_t init; char *buffer; unsigned long length; { int i; - unsigned long cks; + uint16_t cks; cks = init; for(i = 0; i < length; i++) { @@ -531,7 +531,7 @@ static void dd_chksum(hdr, data) struct fileHdr hdr; unsigned char *data; { - unsigned long cks; + uint16_t cks; if(write_it) { cks = dd_checksum(INIT_CRC, (char *)data - CFILEHDRSIZE, @@ -539,7 +539,7 @@ unsigned char *data; if(hdr.datacrc != cks) { (void)fprintf(stderr, "Checksum error on compressed file: need 0x%04x, got 0x%04x\n", - hdr.datacrc, (int)cks); + hdr.datacrc, (uint16_t)cks); #ifdef SCAN do_error("macunpack: Checksum error on compressed file"); #endif /* SCAN */ @@ -548,13 +548,13 @@ unsigned char *data; } } -static unsigned long dd_checkor(init, buffer, length) -unsigned long init; +static uint16_t dd_checkor(init, buffer, length) +uint16_t init; char *buffer; unsigned long length; { int i; - unsigned long cks; + uint16_t cks; cks = init; for(i = 0; i < length; i++) { @@ -625,7 +625,7 @@ static void dd_copy(hdr, data) struct fileHdr hdr; unsigned char *data; { - unsigned long cks; + uint16_t cks; if(write_it) { start_info(info, hdr.rsrcLength, hdr.dataLength); @@ -643,7 +643,7 @@ unsigned char *data; if(hdr.datacrc != cks) { (void)fprintf(stderr, "Checksum error on data fork: need 0x%04x, got 0x%04x\n", - hdr.datacrc, (int)cks); + hdr.datacrc, (uint16_t)cks); #ifdef SCAN do_error("macunpack: Checksum error on data fork"); #endif /* SCAN */ @@ -660,7 +660,7 @@ unsigned char *data; if(hdr.rsrccrc != cks) { (void)fprintf(stderr, "Checksum error on resource fork: need 0x%04x, got 0x%04x\n", - hdr.rsrccrc, (int)cks); + hdr.rsrccrc, (uint16_t)cks); #ifdef SCAN do_error("macunpack: Checksum error on resource fork"); #endif /* SCAN */ @@ -692,7 +692,7 @@ static void dd_expand(hdr, data) struct fileCHdr hdr; unsigned char *data; { - unsigned long cks; + uint16_t cks; char *out_buf; if(write_it) { @@ -715,7 +715,7 @@ unsigned char *data; if(cks != hdr.datacrc2) { (void)fprintf(stderr, "Checksum error on data fork: need 0x%04x, got 0x%04x\n", - (int)hdr.datacrc2, (int)cks); + (uint16_t)hdr.datacrc2, (uint16_t)cks); #ifdef SCAN do_error("macunpack: Checksum error on data fork"); #endif /* SCAN */ @@ -731,7 +731,7 @@ unsigned char *data; } out_buf = out_buffer; dd_expandfile(hdr.rsrcLength, hdr.rsrcCLength, (int)hdr.rsrcmethod, - (int)hdr.rsrcinfo, data, (unsigned long)hdr.rsrccrc); + (int)hdr.rsrcinfo, data, (uint16_t)hdr.rsrccrc); data += hdr.rsrcCLength; if(write_it) { if((hdr.info2 & 0x40) && (hdr.rsrcLength != 0)) { @@ -740,7 +740,7 @@ unsigned char *data; if(cks != hdr.rsrccrc2) { (void)fprintf(stderr, "Checksum error on resource fork: need 0x%04x, got 0x%04x\n", - (int)hdr.rsrccrc2, (int)cks); + (uint16_t)hdr.rsrccrc2, (uint16_t)cks); #ifdef SCAN do_error("macunpack: Checksum error on resource fork"); #endif /* SCAN */ @@ -755,13 +755,14 @@ unsigned char *data; } static void dd_expandfile(obytes, ibytes, method, kind, data, chksum) -unsigned long obytes, ibytes, chksum; +unsigned long obytes, ibytes; +uint16_t chksum; int method, kind; unsigned char *data; { int sub_method, m1, m2; char *optr = out_ptr; - unsigned long cksinit; + uint16_t cksinit; if(obytes == 0) { if(verbose) { @@ -867,7 +868,8 @@ unsigned long obytes; /*---------------------------------------------------------------------------*/ static void dd_lzc(ibytes, obytes, data, mb, chksum, ckinit) unsigned char *data; -unsigned long ibytes, obytes, chksum, ckinit; +unsigned long ibytes, obytes; +uint16_t chksum, ckinit; int mb; { int i; @@ -942,7 +944,7 @@ unsigned long ibytes; /*---------------------------------------------------------------------------*/ static void dd_lzss(data, chksum) unsigned char *data; -unsigned long chksum; +uint16_t chksum; { int i, LZptr, LZbptr, LZlength; char *optr = out_ptr; diff --git a/macunpack/lzh.c b/macunpack/lzh.c index 4e7482b..ec8ee26 100755 --- a/macunpack/lzh.c +++ b/macunpack/lzh.c @@ -369,7 +369,7 @@ int method; int rsrcLength, dataLength; int doit; char *mname; - unsigned long crc; + uint16_t crc; if(filehdr->upsize > lzh_filesize) { if(lzh_filesize == 0) { @@ -562,7 +562,7 @@ int method; if(filehdr->crc != crc) { (void)fprintf(stderr, "CRC error on file: need 0x%04x, got 0x%04x\n", - filehdr->crc, (int)crc); + filehdr->crc, (uint16_t)crc); #ifdef SCAN do_error("macunpack: CRC error on file"); #endif /* SCAN */ diff --git a/macunpack/pit.c b/macunpack/pit.c index 1e3edba..1033bf8 100755 --- a/macunpack/pit.c +++ b/macunpack/pit.c @@ -27,7 +27,7 @@ void pit() struct pit_header filehdr; char pithdr[4]; int decode, synced, ch; - unsigned long data_crc, crc; + uint16_t data_crc, crc; updcrc = binhex_updcrc; crcinit = binhex_crcinit; @@ -137,7 +137,7 @@ void pit() if(crc != data_crc) { (void)fprintf(stderr, "CRC error in file: need 0x%04x, got 0x%04x\n", - (int)crc, (int)data_crc); + (uint16_t)crc, (uint16_t)data_crc); #ifdef SCAN do_error("macunpack: CRC error in file"); #endif /* SCAN */ @@ -165,7 +165,7 @@ struct pit_header *f; int compr; { register int i; - unsigned long crc; + uint16_t crc; int n; char hdr[HDRBYTES]; char ftype[5], fauth[5]; @@ -189,7 +189,7 @@ int compr; if(f->hdrCRC != crc) { (void)fprintf(stderr, "\tHeader CRC mismatch: got 0x%04x, need 0x%04x\n", - f->hdrCRC & WORDMASK, (int)crc); + f->hdrCRC & WORDMASK, (uint16_t)crc); return -1; } diff --git a/macunpack/pit.h b/macunpack/pit.h index f47caeb..40e59a8 100755 --- a/macunpack/pit.h +++ b/macunpack/pit.h @@ -1,3 +1,5 @@ +#include <stdint.h> + #define H_NAMELEN 63 #define H_NLENOFF 0 @@ -24,7 +26,7 @@ struct pit_header { /* Packit file header (92 bytes) */ unsigned long rlen; /* number of bytes in resource fork */ unsigned long ctim; /* file creation time */ unsigned long mtim; /* file modified time */ - unsigned short hdrCRC; /* CRC */ + uint16_t hdrCRC; /* CRC */ }; #define nocomp 0 diff --git a/macunpack/sit.c b/macunpack/sit.c index 614e8ba..61979ae 100755 --- a/macunpack/sit.c +++ b/macunpack/sit.c @@ -159,7 +159,7 @@ struct fileHdr *f; int skip; { register int i; - unsigned long crc; + uint16_t crc; int n; char hdr[FILEHDRSIZE]; char ftype[5], fauth[5]; @@ -177,7 +177,7 @@ int skip; f->hdrCRC = get2(hdr + F_HDRCRC); if(f->hdrCRC != crc) { (void)fprintf(stderr, "Header CRC mismatch: got 0x%04x, need 0x%04x\n", - f->hdrCRC & WORDMASK, (int)crc); + f->hdrCRC & WORDMASK, (uint16_t)crc); return -1; } @@ -392,7 +392,7 @@ char *name; static void sit_unstuff(filehdr) struct fileHdr filehdr; { - unsigned long crc; + uint16_t crc; if(write_it) { start_info(info, filehdr.rsrcLength, filehdr.dataLength); @@ -409,7 +409,7 @@ struct fileHdr filehdr; if(filehdr.rsrcCRC != crc) { (void)fprintf(stderr, "CRC error on resource fork: need 0x%04x, got 0x%04x\n", - filehdr.rsrcCRC, (int)crc); + filehdr.rsrcCRC, (uint16_t)crc); #ifdef SCAN do_error("macunpack: CRC error on resource fork"); #endif /* SCAN */ @@ -428,7 +428,7 @@ struct fileHdr filehdr; if(filehdr.dataCRC != crc) { (void)fprintf(stderr, "CRC error on data fork: need 0x%04x, got 0x%04x\n", - filehdr.dataCRC, (int)crc); + filehdr.dataCRC, (uint16_t)crc); #ifdef SCAN do_error("macunpack: CRC error on data fork"); #endif /* SCAN */ diff --git a/macunpack/sit.h b/macunpack/sit.h index d7f5f7e..a9f014a 100755 --- a/macunpack/sit.h +++ b/macunpack/sit.h @@ -1,3 +1,5 @@ +#include <stdint.h> + #define S_SIGNATURE 0 #define S_NUMFILES 4 #define S_ARCLENGTH 6 @@ -49,10 +51,10 @@ struct fileHdr { /* 112 bytes */ unsigned long dataLength; unsigned long compRLength; /* compressed lengths */ unsigned long compDLength; - unsigned short rsrcCRC; /* crc of rsrc fork */ - unsigned short dataCRC; /* crc of data fork */ + uint16_t rsrcCRC; /* crc of rsrc fork */ + uint16_t dataCRC; /* crc of data fork */ char reserved[6]; - unsigned short hdrCRC; /* crc of file header */ + uint16_t hdrCRC; /* crc of file header */ }; diff --git a/macunpack/zma.c b/macunpack/zma.c index 9bfb32e..58bdb8b 100755 --- a/macunpack/zma.c +++ b/macunpack/zma.c @@ -275,7 +275,7 @@ struct fileHdr fhdr; static void zma_mooz(filehdr) struct fileHdr filehdr; { - unsigned long crc; + uint16_t crc; if(write_it) { start_info(info, filehdr.rsrcLength, filehdr.dataLength); @@ -292,7 +292,7 @@ struct fileHdr filehdr; if(filehdr.dataCRC != crc) { (void)fprintf(stderr, "CRC error on data fork: need 0x%04x, got 0x%04x\n", - (int)filehdr.dataCRC, (int)crc); + (uint16_t)filehdr.dataCRC, (uint16_t)crc); #ifdef SCAN do_error("macunpack: CRC error on data fork"); #endif /* SCAN */ diff --git a/macunpack/zma.h b/macunpack/zma.h index f52a31b..dab7b82 100755 --- a/macunpack/zma.h +++ b/macunpack/zma.h @@ -1,4 +1,5 @@ #include "zmahdr.h" +#include <stdint.h> #define Z_HDRSIZE 78 @@ -37,8 +38,8 @@ struct fileHdr { /* 78 bytes */ unsigned short FndrFlags; /* copy of Finder flags. For our purposes, we can clear: busy,onDesk */ - unsigned short dataCRC; /* Data fork crc */ - unsigned short rsrcCRC; /* Resource fork crc */ + uint16_t dataCRC; /* Data fork crc */ + uint16_t rsrcCRC; /* Resource fork crc */ unsigned char fName[32]; /* a STR32 */ /* The following are overlayed in the original structure */ unsigned long conts; /* Pointer to directory contents */

