[PATCH version 2] guestfish: Use xstrtol to parse integers (RHBZ#557655).
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
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.
On Mon, Jan 25, 2010 at 01:05:32PM +0100, Jim Meyering wrote:
Richard W.M. Jones wrote:
+ 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.
There's a limit to what we can do here. We would have to mark this parameter in a special way in the generator (not 'Int' but 'Int_that_usually_needs_octal_in_guestfish'). While I now think it was a bad idea to use plain types like 'Int' and 'String' in the generator (you live and learn, but this is why we replaced many uses of 'String' with 'Pathname', 'Device' etc), changing this is quite involved for little gain. And what happens if people do want to use decimal modes, eg. if they are generating guestfish scripts. It is also now documented. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
Richard W.M. Jones wrote:
On Mon, Jan 25, 2010 at 01:05:32PM +0100, Jim Meyering wrote:
Richard W.M. Jones wrote:
+ 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.
There's a limit to what we can do here. We would have to mark this parameter in a special way in the generator (not 'Int' but 'Int_that_usually_needs_octal_in_guestfish').
While I now think it was a bad idea to use plain types like 'Int' and 'String' in the generator (you live and learn, but this is why we replaced many uses of 'String' with 'Pathname', 'Device' etc),
Yes, I remember well ;)
changing this is quite involved for little gain. And what happens if people do want to use decimal modes, eg. if they are generating guestfish scripts. It is also now documented.
I agree that it's probably not worth the effort.
Updated again, includes a fix suggested by Jim Meyering, and another fix to handling of fwrite. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
participants (2)
-
Jim Meyering -
Richard W.M. Jones