diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-14 19:50:06 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-14 19:50:06 +0000 |
commit | 7089c31d578d683804598b405e2cdf375cd7ce33 (patch) | |
tree | d341e2416feb70de55b9684a8d03852f5f5f404c | |
parent | c7131c3e58c2cef17263d03ac542f7fbea1ce2db (diff) | |
download | busybox-w32-7089c31d578d683804598b405e2cdf375cd7ce33.tar.gz busybox-w32-7089c31d578d683804598b405e2cdf375cd7ce33.tar.bz2 busybox-w32-7089c31d578d683804598b405e2cdf375cd7ce33.zip |
od: fix "od -b"
-rw-r--r-- | coreutils/od_bloaty.c | 22 | ||||
-rwxr-xr-x | testsuite/od.tests | 17 |
2 files changed, 27 insertions, 12 deletions
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 942cf038e..5e2287534 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -508,10 +508,10 @@ check_and_close(void) | |||
508 | } | 508 | } |
509 | 509 | ||
510 | /* If S points to a single valid modern od format string, put | 510 | /* If S points to a single valid modern od format string, put |
511 | a description of that format in *TSPEC, make *NEXT point at the | 511 | a description of that format in *TSPEC, return pointer to |
512 | character following the just-decoded format (if *NEXT is non-NULL), | 512 | character following the just-decoded format. |
513 | and return zero. For example, if S were "d4afL" | 513 | For example, if S were "d4afL", we will return a rtp to "afL" |
514 | *NEXT would be set to "afL" and *TSPEC would be | 514 | and *TSPEC would be |
515 | { | 515 | { |
516 | fmt = SIGNED_DECIMAL; | 516 | fmt = SIGNED_DECIMAL; |
517 | size = INT or LONG; (whichever integral_type_size[4] resolves to) | 517 | size = INT or LONG; (whichever integral_type_size[4] resolves to) |
@@ -521,9 +521,8 @@ check_and_close(void) | |||
521 | S_ORIG is solely for reporting errors. It should be the full format | 521 | S_ORIG is solely for reporting errors. It should be the full format |
522 | string argument. */ | 522 | string argument. */ |
523 | 523 | ||
524 | static void | 524 | static const char * |
525 | decode_one_format(const char *s_orig, const char *s, const char **next, | 525 | decode_one_format(const char *s_orig, const char *s, struct tspec *tspec) |
526 | struct tspec *tspec) | ||
527 | { | 526 | { |
528 | enum size_spec size_spec; | 527 | enum size_spec size_spec; |
529 | unsigned size; | 528 | unsigned size; |
@@ -536,7 +535,6 @@ decode_one_format(const char *s_orig, const char *s, const char **next, | |||
536 | unsigned field_width = 0; | 535 | unsigned field_width = 0; |
537 | int pos; | 536 | int pos; |
538 | 537 | ||
539 | assert(tspec != NULL); | ||
540 | 538 | ||
541 | switch (*s) { | 539 | switch (*s) { |
542 | case 'd': | 540 | case 'd': |
@@ -562,13 +560,14 @@ decode_one_format(const char *s_orig, const char *s, const char **next, | |||
562 | s = end; | 560 | s = end; |
563 | } | 561 | } |
564 | } else { | 562 | } else { |
565 | static const uint8_t CSIL_sizeof[] = { | 563 | static const uint8_t CSIL_sizeof[4] = { |
566 | sizeof(char), | 564 | sizeof(char), |
567 | sizeof(short), | 565 | sizeof(short), |
568 | sizeof(int), | 566 | sizeof(int), |
569 | sizeof(long), | 567 | sizeof(long), |
570 | }; | 568 | }; |
571 | size = CSIL_sizeof[p - CSIL]; | 569 | size = CSIL_sizeof[p - CSIL]; |
570 | s++; /* skip C/S/I/L */ | ||
572 | } | 571 | } |
573 | 572 | ||
574 | #define ISPEC_TO_FORMAT(Spec, Min_format, Long_format, Max_format) \ | 573 | #define ISPEC_TO_FORMAT(Spec, Min_format, Long_format, Max_format) \ |
@@ -716,8 +715,7 @@ decode_one_format(const char *s_orig, const char *s, const char **next, | |||
716 | if (tspec->hexl_mode_trailer) | 715 | if (tspec->hexl_mode_trailer) |
717 | s++; | 716 | s++; |
718 | 717 | ||
719 | if (next != NULL) | 718 | return s; |
720 | *next = s; | ||
721 | } | 719 | } |
722 | 720 | ||
723 | /* Decode the modern od format string S. Append the decoded | 721 | /* Decode the modern od format string S. Append the decoded |
@@ -733,7 +731,7 @@ decode_format_string(const char *s) | |||
733 | struct tspec tspec; | 731 | struct tspec tspec; |
734 | const char *next; | 732 | const char *next; |
735 | 733 | ||
736 | decode_one_format(s_orig, s, &next, &tspec); | 734 | next = decode_one_format(s_orig, s, &tspec); |
737 | 735 | ||
738 | assert(s != next); | 736 | assert(s != next); |
739 | s = next; | 737 | s = next; |
diff --git a/testsuite/od.tests b/testsuite/od.tests new file mode 100755 index 000000000..60f22d5dd --- /dev/null +++ b/testsuite/od.tests | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/bin/sh | ||
2 | # Copyright 2008 by Denys Vlasenko | ||
3 | # Licensed under GPL v2, see file LICENSE for details. | ||
4 | |||
5 | . testing.sh | ||
6 | |||
7 | # testing "test name" "options" "expected result" "file input" "stdin" | ||
8 | |||
9 | testing "od -b" \ | ||
10 | "echo HELLO | od -b" \ | ||
11 | "\ | ||
12 | 0000000 110 105 114 114 117 012 | ||
13 | 0000006 | ||
14 | " \ | ||
15 | "" "HELLO" | ||
16 | |||
17 | exit $FAILCOUNT | ||