# HG changeset patch # User David A. Holland # Date 1653972852 14400 # Node ID 3aa0f5a02342b824dd355079ab139e639c8d269a # Parent 5b21f127e957f793e746befbae006f6b00fa7c24 Remove unused variable; fix what it was supposed to be doing. (and document it a bit for the next time through here) diff -r 5b21f127e957 -r 3aa0f5a02342 checksum/dosum.c --- a/checksum/dosum.c Mon May 30 23:58:14 2022 -0400 +++ b/checksum/dosum.c Tue May 31 00:54:12 2022 -0400 @@ -66,7 +66,6 @@ uint32_t dosum(const char *buf, size_t len, size_t skipstart, size_t skiplen) { struct sumstate s; - unsigned fudge; size_t numwords; assert(skiplen%2==0); @@ -79,6 +78,18 @@ * * The followed mangled logic that rounds some things up matches * what used to be done in an even uglier way. + * + * To wit: if there's a skip area, we start after it and read pairs + * of octets, including a zero past the end of the file if the + * remaining data length after the skip area has odd size, so as to + * get the last byte. (The caller is responsible for making sure + * there's a zero there.) Then we read the beginning of the file up + * to the skip area, but round down so as to not read the first byte + * of the skip area if skipstart is odd. If skipstart is odd then we + * wedge in that last byte along with a zero. + * + * If there isn't a skip area, we read the whole thing in order, + * including the zero past the end if the size is odd. */ assert(sizeof(uint16_t)==2); @@ -90,9 +101,15 @@ size_t p1 = 0; size_t l1 = (skipstart/2) * 2; - fudge = skipstart%2; sumstate_sum(&s, buf+p0, l0); sumstate_sum(&s, buf+p1, l1); + if (skipstart % 2 == 1) { + char tmp[2]; + + tmp[0] = buf[skipstart - 1]; + tmp[1] = 0; + sumstate_sum(&s, tmp, 2); + } } else { sumstate_sum(&s, buf, numwords * 2);