commit 91ab4e80b92637f2f95f61c73a6c848a35ddddea
parent 1e4ab5ec9a02cc5e17ff1c116baf42efe0874f91
Author: FRIGN <dev@frign.de>
Date: Mon, 26 Oct 2015 17:21:15 +0100
Fix multiple file handling
1) Fix skip overflow for negative numbers
2) Print proper trailing lines and addresses according to the last
element.
Diffstat:
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/od.c b/od.c
@@ -134,7 +134,7 @@ od(FILE *fp, char *fname, int last)
static off_t addr;
size_t buflen;
- while (skip - addr) {
+ while (skip - addr > 0) {
buflen = fread(buf, 1, MIN(skip - addr, BUFSIZ), fp);
addr += buflen;
if (feof(fp) || ferror(fp))
@@ -153,9 +153,10 @@ od(FILE *fp, char *fname, int last)
}
}
}
- if (lineoff)
+ if (lineoff && last)
printline(line, lineoff, addr - lineoff);
- printline((unsigned char *)"", 0, addr);
+ if (last)
+ printline((unsigned char *)"", 0, addr);
}
static int