From nobody Sun Feb 8 16:11:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628616485; cv=none; d=zohomail.com; s=zohoarc; b=AZ6BjieZjOv6Gtai2CAjuff29UNtLUj0o4/EQIhDeoNidtNwy1MFUJxvpTvVm3LMNgmqtHkonOKIWh3o6AYPzPPivBOYo7EfAq3YkITj2M0EjmUBSVp53rfFgPpvVFJYFyKG7G4AEhBxZnz+CAKJw9D5bTlYGRUHwkHKWHP6h5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628616485; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1g+1et0eqYgLgFOiddipbueDa/qJZLSICXowab4XXYM=; b=XLU1PjAwkyhT4A/OZB0cIP+yWvL0dbyOYiCer/DjMFOwIJrRtL3hj4XNeMIk+QlXi9VX/u0FQ+4JjPyDMEchoYDco/zlBehY3hfdZa2swkiWwH/WcI6nQloCYnI+0HYUjZd6SbaCr5Ui/E6gfa2oT8as3I94IgwLclXeYq0CWiQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1628616485503163.77494671071383; Tue, 10 Aug 2021 10:28:05 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-293-m4SDBJ-BNXCsfnrb67z3KQ-1; Tue, 10 Aug 2021 13:28:02 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3140CC73AC; Tue, 10 Aug 2021 17:27:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11CE860BF1; Tue, 10 Aug 2021 17:27:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D50674BB7C; Tue, 10 Aug 2021 17:27:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17AHEnlt021474 for ; Tue, 10 Aug 2021 13:14:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3828D18A77; Tue, 10 Aug 2021 17:14:49 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id B610F136F5 for ; Tue, 10 Aug 2021 17:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628616484; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1g+1et0eqYgLgFOiddipbueDa/qJZLSICXowab4XXYM=; b=HC85BqNPtnhgB7wXAP86INnQhhy0CWExFc164PPImSUh13PlZkFssAI/hIV6//ir/o2wy6 6KxZWkgcHbdr4s5CD1YZls8o1dGGcJnrrnDkkkKAILDKV8S0eMEPQYRYSmREmNjga9J3Co 2IrlLfDOsTO+S2b/PNu2D9+vLD8Ao1E= X-MC-Unique: m4SDBJ-BNXCsfnrb67z3KQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/5] vsh: do not cast away const Date: Tue, 10 Aug 2021 19:14:39 +0200 Message-Id: <2954e6b96a34e84734fcaa69cc0e9bf3750d5994.1628615384.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628616486689100001 Instead of using the same variable to store either a const pointer or an allocated string, always make a copy. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Peter Krempa --- tools/vsh.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 123284c636..3bbaecd2ea 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -318,7 +318,7 @@ vshCmddefCheckInternals(vshControl *ctl, =20 case VSH_OT_ALIAS: { size_t j; - char *name =3D (char *)opt->help; /* cast away const */ + g_autofree char *name =3D NULL; char *p; =20 if (opt->flags || !opt->help) { @@ -326,15 +326,16 @@ vshCmddefCheckInternals(vshControl *ctl, opt->name, cmd->name); return -1; /* alias options are tracked by the original na= me */ } - if ((p =3D strchr(name, '=3D'))) - name =3D g_strndup(name, p - name); + if ((p =3D strchr(opt->help, '=3D'))) + name =3D g_strndup(opt->help, p - opt->help); + else + name =3D g_strdup(opt->help); for (j =3D i + 1; cmd->opts[j].name; j++) { if (STREQ(name, cmd->opts[j].name) && cmd->opts[j].type !=3D VSH_OT_ALIAS) break; } - if (name !=3D opt->help) { - VIR_FREE(name); + if (p) { /* If alias comes with value, replacement must not be bool= */ if (cmd->opts[j].type =3D=3D VSH_OT_BOOL) { vshError(ctl, _("alias '%s' of command '%s' has mismat= ched alias type"), --=20 2.31.1