mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
vsh: do not cast away const
Instead of using the same variable to store either a const pointer or an allocated string, always make a copy. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
2c0f47e75c
commit
2cbc686d66
11
tools/vsh.c
11
tools/vsh.c
@ -318,7 +318,7 @@ vshCmddefCheckInternals(vshControl *ctl,
|
|||||||
|
|
||||||
case VSH_OT_ALIAS: {
|
case VSH_OT_ALIAS: {
|
||||||
size_t j;
|
size_t j;
|
||||||
char *name = (char *)opt->help; /* cast away const */
|
g_autofree char *name = NULL;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (opt->flags || !opt->help) {
|
if (opt->flags || !opt->help) {
|
||||||
@ -326,15 +326,16 @@ vshCmddefCheckInternals(vshControl *ctl,
|
|||||||
opt->name, cmd->name);
|
opt->name, cmd->name);
|
||||||
return -1; /* alias options are tracked by the original name */
|
return -1; /* alias options are tracked by the original name */
|
||||||
}
|
}
|
||||||
if ((p = strchr(name, '=')))
|
if ((p = strchr(opt->help, '=')))
|
||||||
name = g_strndup(name, p - name);
|
name = g_strndup(opt->help, p - opt->help);
|
||||||
|
else
|
||||||
|
name = g_strdup(opt->help);
|
||||||
for (j = i + 1; cmd->opts[j].name; j++) {
|
for (j = i + 1; cmd->opts[j].name; j++) {
|
||||||
if (STREQ(name, cmd->opts[j].name) &&
|
if (STREQ(name, cmd->opts[j].name) &&
|
||||||
cmd->opts[j].type != VSH_OT_ALIAS)
|
cmd->opts[j].type != VSH_OT_ALIAS)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (name != opt->help) {
|
if (p) {
|
||||||
VIR_FREE(name);
|
|
||||||
/* If alias comes with value, replacement must not be bool */
|
/* If alias comes with value, replacement must not be bool */
|
||||||
if (cmd->opts[j].type == VSH_OT_BOOL) {
|
if (cmd->opts[j].type == VSH_OT_BOOL) {
|
||||||
vshError(ctl, _("alias '%s' of command '%s' has mismatched alias type"),
|
vshError(ctl, _("alias '%s' of command '%s' has mismatched alias type"),
|
||||||
|
Loading…
Reference in New Issue
Block a user