bsdiff-portable

A more portable version of Colin Percival's bsdiff
git clone git://git.sgregoratto.me/bsdiff-portable
Log | Files | Refs | README | LICENSE

commit 02a49ca2da7e7def1e268082ae5396cd5f4a848c
parent 1c7657ae475ed3188876fd101ccb04195697efef
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Fri, 25 Sep 2020 14:01:50 +1000

increase max line length to 100

Contorting the code to fit into 80 columns reduced legibility
significantly.

Diffstat:
M.clang-format | 2+-
Mbsdiff.c | 25+++++++++----------------
Mbspatch.c | 13++++---------
3 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/.clang-format b/.clang-format @@ -4,7 +4,7 @@ AlignConsecutiveMacros: true #AlignConsecutiveLists: true #BitFieldDeclarationsOnePerLine: true BreakBeforeBraces: Mozilla -ColumnLimit: 80 +ColumnLimit: 100 ContinuationIndentWidth: 4 Cpp11BracedListStyle: false FixNamespaceComments: true diff --git a/bsdiff.c b/bsdiff.c @@ -84,7 +84,7 @@ main(int argc, char **argv) off_t dblen; uint8_t *dbuf; uint8_t ctrlbuf[24]; - struct bsdiff_header header = {"BSDIFF40", 0, 0, 0}; + struct bsdiff_header header = { "BSDIFF40", 0, 0, 0 }; FILE *pf; if (argc != 4) @@ -102,7 +102,7 @@ main(int argc, char **argv) if (pledge("stdio rpath wpath cpath", NULL) == -1) err(1, "pledge"); #endif - old = readfile(argv[1], &oldsize, &(struct stat){0}); + old = readfile(argv[1], &oldsize, &(struct stat){ 0 }); if ((I = reallocarray(NULL, oldsize + 1, sizeof(off_t))) == NULL) err(1, "reallocarray"); @@ -113,7 +113,7 @@ main(int argc, char **argv) free(V); - new = readfile(argv[2], &newsize, &(struct stat){0}); + new = readfile(argv[2], &newsize, &(struct stat){ 0 }); #if HAVE_PLEDGE && HAVE_UNVEIL if (pledge("stdio wpath cpath", NULL) == -1) err(1, "pledge"); @@ -173,20 +173,17 @@ main(int argc, char **argv) prev_oldscore = oldscore; prev_pos = pos; - len = search(I, old, oldsize, new + scan, - newsize - scan, 0, oldsize, &pos); + len = search(I, old, oldsize, new + scan, newsize - scan, 0, oldsize, &pos); for (; scsc < scan + len; scsc++) if (scsc + lastoffset < oldsize && old[scsc + lastoffset] == new[scsc]) oldscore++; - if ((len == oldscore && len != 0) || - len > oldscore + 8) + if ((len == oldscore && len != 0) || len > oldscore + 8) break; - if (scan + lastoffset < oldsize && - old[scan + lastoffset] == new[scan]) + if (scan + lastoffset < oldsize && old[scan + lastoffset] == new[scan]) oldscore--; const off_t fuzz = 8; @@ -204,8 +201,7 @@ main(int argc, char **argv) if (len != oldscore || scan == newsize) { s = Sf = lenf = 0; - for (i = 0; lastscan + i < scan && - lastpos + i < oldsize;) { + for (i = 0; lastscan + i < scan && lastpos + i < oldsize;) { if (old[lastpos + i] == new[lastscan + i]) s++; i++; @@ -218,9 +214,7 @@ main(int argc, char **argv) lenb = 0; if (scan < newsize) { s = Sb = 0; - for (i = 1; - scan >= lastscan + i && pos >= i; - i++) { + for (i = 1; scan >= lastscan + i && pos >= i; i++) { if (old[pos - i] == new[scan - i]) s++; if (s * 2 - i > Sb * 2 - lenb) { @@ -237,8 +231,7 @@ main(int argc, char **argv) if (new[lastscan + lenf - overlap + i] == old[lastpos + lenf - overlap + i]) s++; - if (new[scan - lenb + i] == - old[pos - lenb + i]) + if (new[scan - lenb + i] == old[pos - lenb + i]) s--; if (s > Ss) { Ss = s; diff --git a/bspatch.c b/bspatch.c @@ -121,7 +121,7 @@ main(int argc, char **argv) bzctrllen = offtin(header + 8); bzdatalen = offtin(header + 16); newsize = offtin(header + 24); - if ((bzctrllen < 0) || (bzdatalen < 0) || (newsize < 0)) + if (bzctrllen < 0 || bzdatalen < 0 || newsize < 0) errx(1, "Corrupt patch"); /* Close patch file and re-open it via libbzip2 at the right places */ @@ -146,8 +146,7 @@ main(int argc, char **argv) /* Read control data */ for (i = 0; i <= 2; i++) { lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8); - if ((lenread < 8) || - ((cbz2err != BZ_OK) && (cbz2err != BZ_STREAM_END))) + if (lenread < 8 || (cbz2err != BZ_OK && cbz2err != BZ_STREAM_END)) errx(1, "Corrupt patch"); ctrl[i] = offtin(buf); } @@ -155,15 +154,12 @@ main(int argc, char **argv) /* Sanity-check */ if (ctrl[0] < 0 || ctrl[1] < 0) errx(1, "Corrupt patch"); - - /* Sanity-check */ if (newpos + ctrl[0] > newsize) errx(1, "Corrupt patch"); /* Read diff string */ lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]); - if (lenread < ctrl[0] || - (dbz2err != BZ_OK && dbz2err != BZ_STREAM_END)) + if (lenread < ctrl[0] || (dbz2err != BZ_OK && dbz2err != BZ_STREAM_END)) errx(1, "Corrupt patch"); /* Add old data to diff string */ @@ -181,8 +177,7 @@ main(int argc, char **argv) /* Read extra string */ lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]); - if (lenread < ctrl[1] || - (ebz2err != BZ_OK && ebz2err != BZ_STREAM_END)) + if (lenread < ctrl[1] || (ebz2err != BZ_OK && ebz2err != BZ_STREAM_END)) errx(1, "Corrupt patch"); /* Adjust pointers */