Re: [PATCH] virsh: Convert escape sequence string to uppercase

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

 



On 12/13/2011 01:34 AM, Michal Privoznik wrote:
> Macro for translating escape sequence to char expects it to be
> all uppercase. Without this, various lowercase sequences are
> malformed: e.g. ^e gets translated to %.
> ---
>  tools/virsh.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index d58b827..ff8b3d2 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -17776,6 +17776,11 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
>              if ((len == 2 && *optarg == '^') ||
>                  (len == 1 && *optarg != '^')) {
>                  ctl->escapeChar = optarg;
> +                while (*optarg) {
> +                    if (islower(*optarg))
> +                        *optarg = toupper(*optarg);
> +                    optarg++;
> +                }

This should be using functions gnulib's "c-ctype.h", so that we are
locale-independent.  For that matter, c_toupper is nicer than toupper,
in that it is intentionally well-defined on all inputs, while toupper
requires pre-filtering with islower.

Also, why do we need a while loop?  We only need to convert one byte,
since we just validated length.  And if the user _didn't_ pass the '^a'
syntax, but passed a single character, I don't think we want to convert
optarg[0].

That is, I think this one-liner is a better patch:

diff --git i/tools/virsh.c w/tools/virsh.c
index a95784d..049fd24 100644
--- i/tools/virsh.c
+++ w/tools/virsh.c
@@ -17781,6 +17781,7 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)

             if ((len == 2 && *optarg == '^') ||
                 (len == 1 && *optarg != '^')) {
+                optarg[1] = c_toupper(optarg[1]);
                 ctl->escapeChar = optarg;
             } else {
                 vshError(ctl, _("Invalid string '%s' for escape sequence"),


-- 
Eric Blake   eblake@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]