[PATCH] od_bloaty: fix floating point output
Denys Vlasenko
vda.linux at googlemail.com
Wed Jul 19 11:13:15 UTC 2017
Applied, thanks!
On Wed, Jul 19, 2017 at 11:43 AM, Ron Yorston <rmy at pobox.com> wrote:
> 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 at pobox.com>
> ---
> coreutils/od_bloaty.c | 3 ++-
> testsuite/od.tests | 10 ++++++++++
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
> 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)
> fmt = FLOATING_POINT;
> ++s;
> p = strchr(FDL, *s);
> - if (!p) {
> + if (!p || *p == '\0') {
> size = sizeof(double);
> if (isdigit(s[0])) {
> size = bb_strtou(s, &end, 0);
> @@ -686,6 +686,7 @@ decode_one_format(const char *s_orig, const char *s, struct tspec *tspec)
> };
>
> size = FDL_sizeof[p - FDL];
> + s++; /* skip F/D/L */
> }
>
> 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" \
> "" "HELLO"
> SKIP=
>
> +optional DESKTOP
> +testing "od -f" \
> + "od -f" \
> +"\
> +0000000 0.0000000e+00 0.0000000e+00
> +0000010
> +" \
> + "" "\x00\x00\x00\x00\x00\x00\x00\x00"
> +SKIP=
> +
> optional DESKTOP LONG_OPTS
> testing "od -b --traditional" \
> "od -b --traditional" \
> --
> 2.13.3
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
More information about the busybox
mailing list