[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH version 2] guestfish: Use xstrtol to parse integers (RHBZ#557655).



Richard W.M. Jones wrote:
> Subject: [PATCH] guestfish: Use xstrtol to parse integers (RHBZ#557655).
>
> Current code uses atoi to parse the generator Int type and
> atoll to parse the generator Int64 type.  The problem with the
> ato* functions is that they don't cope with errors very well,
> and they cannot parse numbers that begin with 0.. or 0x..
> for octal and hexadecimal respectively.
>
> This replaces the atoi call with a call to Gnulib xstrtol
> and the atoll call with a call to Gnulib xstrtoll.
>
> The generated code looks like this for all Int arguments:

looks fine.
...
> and like this for all Int64 arguments (note we don't need the
> range check for these):
...
looks fine, too.

> diff --git a/.gitignore b/.gitignore
...
> diff --git a/fish/guestfish.pod b/fish/guestfish.pod
...
> +=head1 NUMBERS
> +
> +Commands which take integers as parameters use the C convention which
> +is to use C<0> to prefix an octal number or C<0x> to prefix a
> +hexadecimal number.  For example:
> +
> + 1234      decimal number 1234
> + 02322     octal number, equivalent to decimal 1234
> + 0x4d2     hexadecimal number, equivalent to decimal 1234
> +
> +When using the C<chmod> command, you almost always want to specify an
> +octal number for the mode, and you must prefix it with C<0> (unlike
> +the Unix L<chmod(1)> program):
> +
> + chmod 0777 /public  # OK
> + chmod 777 /public   # WRONG! This is mode 777 decimal = 01411 octal.

This strikes me as surprising enough that it would deserve
to emit a warning when there is no leading 0.
Doing anything else seems like just asking for trouble.

...
Good test coverage.
The rest looked fine, too.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]