Re: [hackers] [sbase][PATCH] od: Fix argument parsing for -t flag

From: Michael Forney <mforney_AT_mforney.org>
Date: Tue, 3 Mar 2020 14:50:34 -0800

On 2020-02-16, Quentin Rameau <quinq_AT_fifth.space> wrote:
> I think something like that is better, what do you think?

Thanks, this looks good to me. Please resend with a commit message.

> diff --git a/od.c b/od.c
> index 0b1c5c6..9ff8ff2 100644
> --- a/od.c
> +++ b/od.c
> _AT_@ -212,7 +212,7 @@ main(int argc, char *argv[])
> {
> int fd;
> struct type *t;
> - int ret = 0, len;
> + int ret = 0, len, defbytes;
> char *s;
>
> big_endian = (*(uint16_t *)"\0\xff" == 0xff);
> _AT_@ -260,6 +260,7 @@ main(int argc, char *argv[])
> case 'o':
> case 'u':
> case 'x':
> + defbytes = 0;
> /* todo: allow multiple digits */
> if (*(s+1) > '0' && *(s+1) <= '9') {
> len = *(s+1) - '0';
> _AT_@ -271,17 +272,17 @@ main(int argc, char *argv[])
> case 'S':
> len = sizeof(short);
> break;
> + default:
> + defbytes = 1;
> case 'I':
> len = sizeof(int);
> break;
> case 'L':
> len = sizeof(long);
> break;
> - default:
> - len = sizeof(int);
> }
> }
> - addtype(*s++, len);
> + addtype(defbytes ? *s : *s++, len);

I think the increment should be separate for clarity; defbytes isn't
really controlling the parameter, just whether or not s is advanced.

        addtype(*s, len);
        if (!defbytes)
                s++;

> break;
> default:
> usage();
>
>
Received on Tue Mar 03 2020 - 23:50:34 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 04 2020 - 01:00:37 CET