[libvirt] [PATCH 1/2] virsh: change vshCommandOptString return type and fix const-correctness
Eric Blake
eblake at redhat.com
Tue Mar 8 18:11:50 UTC 2011
On 03/08/2011 09:29 AM, Michal Privoznik wrote:
> This function should return pointer to const, because we don't want
> to change command option value. Therfore we can ensure const-correcntess.
s/Therfore/Therefore/; s/correcntess/correctness/
> +++ b/tools/virsh.c
> @@ -255,7 +255,7 @@ static vshCmdOpt *vshCommandOpt(const vshCmd *cmd, const char *name);
> static int vshCommandOptInt(const vshCmd *cmd, const char *name, int *found);
> static unsigned long vshCommandOptUL(const vshCmd *cmd, const char *name,
> int *found);
> -static char *vshCommandOptString(const vshCmd *cmd, const char *name,
> +static const char *vshCommandOptString(const vshCmd *cmd, const char *name,
> int *found);
Indentation.
Most of this patch looks mechanical, and since it still compilers, that
means you pretty much did it correctly.
> @@ -9529,8 +9536,7 @@ cmdCd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> dir = vshCommandOptString(cmd, "dir", &found);
> if (!found) {
> uid_t uid = geteuid();
> - dir = virGetUserDirectory(uid);
> - dir_malloced = !!dir;
> + dir = dir_malloced = virGetUserDirectory(uid);
> }
> if (!dir)
> dir = "/";
> @@ -9541,7 +9547,7 @@ cmdCd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> }
>
> if (dir_malloced)
> - VIR_FREE(dir);
> + VIR_FREE(dir_malloced);
Fails the useless-if-before-free 'make syntax-check' now that
dir_malloced is a (possibly-NULL) pointer rather than a bool.
ACK with those nits fixed, so I'm pushing with this squashed in:
diff --git i/tools/virsh.c w/tools/virsh.c
index 6ad4089..f7e1474 100644
--- i/tools/virsh.c
+++ w/tools/virsh.c
@@ -256,7 +256,7 @@ static int vshCommandOptInt(const vshCmd *cmd, const
char *name, int *found);
static unsigned long vshCommandOptUL(const vshCmd *cmd, const char *name,
int *found);
static const char *vshCommandOptString(const vshCmd *cmd, const char *name,
- int *found);
+ int *found);
static long long vshCommandOptLongLong(const vshCmd *cmd, const char *name,
int *found);
static int vshCommandOptBool(const vshCmd *cmd, const char *name);
@@ -9546,8 +9546,7 @@ cmdCd(vshControl *ctl, const vshCmd *cmd
ATTRIBUTE_UNUSED)
ret = FALSE;
}
- if (dir_malloced)
- VIR_FREE(dir_malloced);
+ VIR_FREE(dir_malloced);
return ret;
}
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110308/68b523f3/attachment-0001.sig>
More information about the libvir-list
mailing list