aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-07-19 10:43:10 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-19 13:12:02 +0200
commita165603d24dc3b5080859abfa834d092f456489d (patch)
treecc418520ca4343d57cb99678187e76e991885c0e
parent9880f86d6e68a2a9b0d691ad0667f38d73eb89e0 (diff)
downloadbusybox-w32-a165603d24dc3b5080859abfa834d092f456489d.tar.gz
busybox-w32-a165603d24dc3b5080859abfa834d092f456489d.tar.bz2
busybox-w32-a165603d24dc3b5080859abfa834d092f456489d.zip
od_bloaty: fix floating point output
Currently od_bloaty does this: $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | busybox od -f od: invalid character 'F' in type string 'fF' $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | busybox od -t fD od: invalid character 'D' in type string 'fD' $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | busybox od -t f 0000000 0000010 The first two occur because the alphabetic length specifier isn't being properly skipped. The third is due to the empty length specifier being treated as alphabetic so we fall off the end of the FDL_sizeof array with undetermined consequences. Coreutils defaults to printing a double in this case. With this patch the output is: $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | ./busybox od -f 0000000 0.0000000e+00 0.0000000e+00 0000010 $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | ./busybox od -t fD 0000000 0.000000000000000e+00 0000010 $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | ./busybox od -t f 0000000 0.000000000000000e+00 0000010 I guess nobody uses BusyBox od to print floating point numbers. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/od_bloaty.c3
-rwxr-xr-xtestsuite/od.tests10
2 files changed, 12 insertions, 1 deletions
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index f13bdfc11..fa0196ca4 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -665,7 +665,7 @@ decode_one_format(const char *s_orig, const char *s, struct tspec *tspec)
665 fmt = FLOATING_POINT; 665 fmt = FLOATING_POINT;
666 ++s; 666 ++s;
667 p = strchr(FDL, *s); 667 p = strchr(FDL, *s);
668 if (!p) { 668 if (!p || *p == '\0') {
669 size = sizeof(double); 669 size = sizeof(double);
670 if (isdigit(s[0])) { 670 if (isdigit(s[0])) {
671 size = bb_strtou(s, &end, 0); 671 size = bb_strtou(s, &end, 0);
@@ -686,6 +686,7 @@ decode_one_format(const char *s_orig, const char *s, struct tspec *tspec)
686 }; 686 };
687 687
688 size = FDL_sizeof[p - FDL]; 688 size = FDL_sizeof[p - FDL];
689 s++; /* skip F/D/L */
689 } 690 }
690 691
691 size_spec = fp_type_size[size]; 692 size_spec = fp_type_size[size];
diff --git a/testsuite/od.tests b/testsuite/od.tests
index 7a9da3e97..0880e0d2f 100755
--- a/testsuite/od.tests
+++ b/testsuite/od.tests
@@ -16,6 +16,16 @@ testing "od -b" \
16 "" "HELLO" 16 "" "HELLO"
17SKIP= 17SKIP=
18 18
19optional DESKTOP
20testing "od -f" \
21 "od -f" \
22"\
230000000 0.0000000e+00 0.0000000e+00
240000010
25" \
26 "" "\x00\x00\x00\x00\x00\x00\x00\x00"
27SKIP=
28
19optional DESKTOP LONG_OPTS 29optional DESKTOP LONG_OPTS
20testing "od -b --traditional" \ 30testing "od -b --traditional" \
21 "od -b --traditional" \ 31 "od -b --traditional" \