diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-03 16:27:54 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-03 16:29:06 +0200 |
commit | e5d5f5b9a770de5a48d1a3bd293d5d611d6624c4 (patch) | |
tree | 64d7021ed5058bf9647778e24fda5ab1656d686c /libbb | |
parent | 9634e8a7d545283c662992d4d3e4a1bcd557c055 (diff) | |
download | busybox-e5d5f5b9a770de5a48d1a3bd293d5d611d6624c4.tar.gz |
hexdump: fix short file of zero butes treated as dup
function old new delta
bb_dump_dump 1466 1491 +25
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/dump.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/libbb/dump.c b/libbb/dump.c index 5941ef902..b4b49d709 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -387,7 +387,10 @@ static unsigned char *get(priv_dumper_t *dumper) if (need == blocksize) { return NULL; } - if (dumper->pub.dump_vflag != ALL && !memcmp(dumper->get__curp, dumper->get__savp, nread)) { + if (dumper->pub.dump_vflag != ALL /* not "show all"? */ + && dumper->pub.dump_vflag != FIRST /* not first line? */ + && memcmp(dumper->get__curp, dumper->get__savp, nread) == 0 /* same data? */ + ) { if (dumper->pub.dump_vflag != DUP) { puts("*"); } @@ -399,7 +402,7 @@ static unsigned char *get(priv_dumper_t *dumper) } n = fread(dumper->get__curp + nread, sizeof(unsigned char), dumper->pub.dump_length == -1 ? need : MIN(dumper->pub.dump_length, need), stdin); - if (!n) { + if (n == 0) { if (ferror(stdin)) { bb_simple_perror_msg(dumper->argv[-1]); } @@ -411,9 +414,10 @@ static unsigned char *get(priv_dumper_t *dumper) dumper->pub.dump_length -= n; } need -= n; - if (!need) { - if (dumper->pub.dump_vflag == ALL || dumper->pub.dump_vflag == FIRST - || memcmp(dumper->get__curp, dumper->get__savp, blocksize) + if (need == 0) { + if (dumper->pub.dump_vflag == ALL /* "show all"? */ + || dumper->pub.dump_vflag == FIRST /* first line? */ + || memcmp(dumper->get__curp, dumper->get__savp, blocksize) != 0 /* not same data? */ ) { if (dumper->pub.dump_vflag == DUP || dumper->pub.dump_vflag == FIRST) { dumper->pub.dump_vflag = WAIT; |