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-w32-e5d5f5b9a770de5a48d1a3bd293d5d611d6624c4.tar.gz busybox-w32-e5d5f5b9a770de5a48d1a3bd293d5d611d6624c4.tar.bz2 busybox-w32-e5d5f5b9a770de5a48d1a3bd293d5d611d6624c4.zip |
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) | |||
387 | if (need == blocksize) { | 387 | if (need == blocksize) { |
388 | return NULL; | 388 | return NULL; |
389 | } | 389 | } |
390 | if (dumper->pub.dump_vflag != ALL && !memcmp(dumper->get__curp, dumper->get__savp, nread)) { | 390 | if (dumper->pub.dump_vflag != ALL /* not "show all"? */ |
391 | && dumper->pub.dump_vflag != FIRST /* not first line? */ | ||
392 | && memcmp(dumper->get__curp, dumper->get__savp, nread) == 0 /* same data? */ | ||
393 | ) { | ||
391 | if (dumper->pub.dump_vflag != DUP) { | 394 | if (dumper->pub.dump_vflag != DUP) { |
392 | puts("*"); | 395 | puts("*"); |
393 | } | 396 | } |
@@ -399,7 +402,7 @@ static unsigned char *get(priv_dumper_t *dumper) | |||
399 | } | 402 | } |
400 | n = fread(dumper->get__curp + nread, sizeof(unsigned char), | 403 | n = fread(dumper->get__curp + nread, sizeof(unsigned char), |
401 | dumper->pub.dump_length == -1 ? need : MIN(dumper->pub.dump_length, need), stdin); | 404 | dumper->pub.dump_length == -1 ? need : MIN(dumper->pub.dump_length, need), stdin); |
402 | if (!n) { | 405 | if (n == 0) { |
403 | if (ferror(stdin)) { | 406 | if (ferror(stdin)) { |
404 | bb_simple_perror_msg(dumper->argv[-1]); | 407 | bb_simple_perror_msg(dumper->argv[-1]); |
405 | } | 408 | } |
@@ -411,9 +414,10 @@ static unsigned char *get(priv_dumper_t *dumper) | |||
411 | dumper->pub.dump_length -= n; | 414 | dumper->pub.dump_length -= n; |
412 | } | 415 | } |
413 | need -= n; | 416 | need -= n; |
414 | if (!need) { | 417 | if (need == 0) { |
415 | if (dumper->pub.dump_vflag == ALL || dumper->pub.dump_vflag == FIRST | 418 | if (dumper->pub.dump_vflag == ALL /* "show all"? */ |
416 | || memcmp(dumper->get__curp, dumper->get__savp, blocksize) | 419 | || dumper->pub.dump_vflag == FIRST /* first line? */ |
420 | || memcmp(dumper->get__curp, dumper->get__savp, blocksize) != 0 /* not same data? */ | ||
417 | ) { | 421 | ) { |
418 | if (dumper->pub.dump_vflag == DUP || dumper->pub.dump_vflag == FIRST) { | 422 | if (dumper->pub.dump_vflag == DUP || dumper->pub.dump_vflag == FIRST) { |
419 | dumper->pub.dump_vflag = WAIT; | 423 | dumper->pub.dump_vflag = WAIT; |