commit 8621c464b1ddf50ffcd7cf8c65e915d2c74ddccc
parent 7661cd30aa1c94db598b4361f97a43a3be1729ce
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date: Wed, 23 Sep 2020 21:02:08 +1000
make error reporting consistent
Diffstat:
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/bspatch.c b/bspatch.c
@@ -62,7 +62,7 @@ main(int argc, char **argv)
/* Open patch file */
if ((f = fopen(argv[3], "r")) == NULL)
- err(1, "fopen(%s)", argv[3]);
+ err(1, "%s: fopen", argv[3]);
/*
File format:
@@ -79,22 +79,22 @@ main(int argc, char **argv)
*/
/* Read header */
- if (fread(header, 1, 32, f) < 32) {
+ if (fread(header, 1, 32, f) == 0) {
if (feof(f))
- errx(1, "Corrupt patch\n");
+ errx(1, "Corrupt patch");
err(1, "fread(%s)", argv[3]);
}
/* Check for appropriate magic */
if (memcmp(header, "BSDIFF40", 8) != 0)
- errx(1, "Corrupt patch\n");
+ errx(1, "Corrupt patch");
/* Read lengths from header */
bzctrllen = offtin(header + 8);
bzdatalen = offtin(header + 16);
newsize = offtin(header + 24);
if ((bzctrllen < 0) || (bzdatalen < 0) || (newsize < 0))
- errx(1, "Corrupt patch\n");
+ errx(1, "Corrupt patch");
/* Close patch file and re-open it via libbzip2 at the right places */
if (fclose(f))
@@ -131,23 +131,23 @@ main(int argc, char **argv)
lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8);
if ((lenread < 8) ||
((cbz2err != BZ_OK) && (cbz2err != BZ_STREAM_END)))
- errx(1, "Corrupt patch\n");
+ errx(1, "Corrupt patch");
ctrl[i] = offtin(buf);
- };
+ }
/* Sanity-check */
if ((ctrl[0] < 0) || (ctrl[1] < 0))
- errx(1, "Corrupt patch\n");
+ errx(1, "Corrupt patch");
/* Sanity-check */
if (newpos + ctrl[0] > newsize)
- errx(1, "Corrupt patch\n");
+ 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)))
- errx(1, "Corrupt patch\n");
+ errx(1, "Corrupt patch");
/* Add old data to diff string */
for (i = 0; i < ctrl[0]; i++)