From nobody Tue Apr 30 16:47:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1614768358; cv=none; d=zohomail.com; s=zohoarc; b=Fv1O/JIeeBuDWJoIxiu8qsUByOkjk/Dihhu/pXnWDzGMQ9atzkxddDOr/3P345IVd4dx1insGTjWoctFKoi8eiq0AC6lf+9vJpMICEAk0DS66QRr31uPEWGEQPuSLA8LqFn+xw94iK+8azbRmhHD2Ozu7AzzO+elgsFfLZ0aPo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614768358; 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=rDJVmM+ReO17f1gwkTcMwf+Bm/vGTid7+EwJPbvvIL0=; b=L0fGsf8ZIkbXjR0Ie9pGUbJXy39R//stSCAtmWGJ6NmAXqQl/6yG3omuvW1W5uDAXgNovu+sdG6t6UfZCGRB0i51SkC/f9Wzf1yJsEiaBDQuMzEWqTtzgwOP2q1Vwad8t5U3bT4EtCWtn5EJlEepnjTGmL4rfYExBlJdz16atrU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 161476835801136.31637757813178; Wed, 3 Mar 2021 02:45:58 -0800 (PST) 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-566-iTEPcsOGMNieLWP2__rAhw-1; Wed, 03 Mar 2021 05:45:54 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10A1D189C447; Wed, 3 Mar 2021 10:45:48 +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 E05506F7EA; Wed, 3 Mar 2021 10:45:47 +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 9363058079; Wed, 3 Mar 2021 10:45:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 123Ajhno027918 for ; Wed, 3 Mar 2021 05:45:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 583E4669EC; Wed, 3 Mar 2021 10:45:43 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8ADB66FFF for ; Wed, 3 Mar 2021 10:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614768356; 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=rDJVmM+ReO17f1gwkTcMwf+Bm/vGTid7+EwJPbvvIL0=; b=HzILJButu4xqGSv3lMJHFlssXLNk9rVh0iYdhYJPar6jYSeDjKoeNaIXlYsJKSawpOvMqS FTB2rc0aw3yx9zLHUyF+De/99HNFG2QlK7WTVyTr7yWhd0ad9bxBE02zp2lnfMz44yQYGg uBsaib5POAZV+hapeTGGn/CQxzjzsZU= X-MC-Unique: iTEPcsOGMNieLWP2__rAhw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] virIndexToDiskName: Make 'idx' unsigned and remove check Date: Wed, 3 Mar 2021 11:45:33 +0100 Message-Id: <9db0d6c68a591b71455b317e07c394b0eb4e4eb4.1614768104.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.11 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We can remove the check that 'idx' is negative by forcing callers to pass unsigned numbers, which they do already or have a check that 'idx' is positive. This in turn allows us to remove most return value NULL checks. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virutil.c | 8 +------- src/util/virutil.h | 2 +- src/vmx/vmx.c | 12 ------------ src/vz/vz_sdk.c | 3 --- 4 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index a0cd0f1bcd..700ec02725 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -430,19 +430,13 @@ int virDiskNameToIndex(const char *name) return idx; } -char *virIndexToDiskName(int idx, const char *prefix) +char *virIndexToDiskName(unsigned int idx, const char *prefix) { char *name =3D NULL; size_t i; int ctr; int offset; - if (idx < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Disk index %d is negative"), idx); - return NULL; - } - for (i =3D 0, ctr =3D idx; ctr >=3D 0; ++i, ctr =3D ctr / 26 - 1) { } offset =3D strlen(prefix); diff --git a/src/util/virutil.h b/src/util/virutil.h index 46328727c1..854b494890 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -56,7 +56,7 @@ virFormatIntPretty(unsigned long long val, int virDiskNameParse(const char *name, int *disk, int *partition); int virDiskNameToIndex(const char* str); -char *virIndexToDiskName(int idx, const char *prefix); +char *virIndexToDiskName(unsigned int idx, const char *prefix); /* No-op workarounds for functionality missing in mingw. */ #ifndef WITH_GETUID diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 73bf7c4f3d..76d01a36de 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2217,9 +2217,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con (*def)->dst =3D virIndexToDiskName (controllerOrBus * 15 + (unit < 7 ? unit : unit - 1), "sd= "); - - if ((*def)->dst =3D=3D NULL) - goto cleanup; } else if (busType =3D=3D VIR_DOMAIN_DISK_BUS_SATA) { if (controllerOrBus < 0 || controllerOrBus > 3) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2238,9 +2235,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con prefix =3D g_strdup_printf("sata%d:%d", controllerOrBus, unit); (*def)->dst =3D virIndexToDiskName(controllerOrBus * 30 + unit= , "sd"); - - if ((*def)->dst =3D=3D NULL) - goto cleanup; } else if (busType =3D=3D VIR_DOMAIN_DISK_BUS_IDE) { if (controllerOrBus < 0 || controllerOrBus > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2258,9 +2252,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con prefix =3D g_strdup_printf("ide%d:%d", controllerOrBus, unit); (*def)->dst =3D virIndexToDiskName(controllerOrBus * 2 + unit,= "hd"); - - if ((*def)->dst =3D=3D NULL) - goto cleanup; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported bus type '%s' for device type '%= s'"), @@ -2287,9 +2278,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con prefix =3D g_strdup_printf("floppy%d", unit); (*def)->dst =3D virIndexToDiskName(unit, "fd"); - - if ((*def)->dst =3D=3D NULL) - goto cleanup; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported bus type '%s' for device type '%= s'"), diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 6f712c7a31..d8548e5a3c 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -626,9 +626,6 @@ prlsdkGetDiskId(PRL_HANDLE disk, int *bus, char **dst) return -1; } - if (NULL =3D=3D *dst) - return -1; - return 0; } --=20 2.29.2 From nobody Tue Apr 30 16:47:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1614768368; cv=none; d=zohomail.com; s=zohoarc; b=P99vdtwNTZhZUKSvon7cx14FwA1NPG0EHqF2saNmHtbKBn7AR2QP9UXZa4VcSuvvDdstU6NEDfUAhfHjdGFK/nt0okUpx2v9S+kmKYsrxBAX47EUfbl2U0cgK+edd4l9LEr3lQID/HKyrFthvabOe5+0hsK2n8oZ1zhURaxTJzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614768368; 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=ENVBQDpqXBN1LgJD2p08QVsi9kKPtTdwdDCevn5tZtk=; b=lP6VXZtzM6sMVdXEJ4/YQ+sqVuRcJVQiKgnoz5AIncZ2ksT7ifEt2M7HMmewuVcqsZNC5IxfIaeu3SYcekKq7kM/CBQBBl4doFmKypsALdi8jQufhfrvhkfHdNB+6KUSjOsORVGu57m4jod+whTbqOoggYGVHDBt0CV2Kkr4f9s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614768368165914.0217032007242; Wed, 3 Mar 2021 02:46:08 -0800 (PST) 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-274-0cwx6LktN-OG7R4Ku81WOQ-1; Wed, 03 Mar 2021 05:46:05 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1E79107ACE3; Wed, 3 Mar 2021 10:45:58 +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 AFB005D9E4; Wed, 3 Mar 2021 10:45:58 +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 7A9565807B; Wed, 3 Mar 2021 10:45:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 123AjiJS027933 for ; Wed, 3 Mar 2021 05:45:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 615325D768; Wed, 3 Mar 2021 10:45:44 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA18D6A8EF for ; Wed, 3 Mar 2021 10:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614768367; 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=ENVBQDpqXBN1LgJD2p08QVsi9kKPtTdwdDCevn5tZtk=; b=ZyhFijxt/N1U2kSUEuobjd3QPZnsKqn3L0nqP5FUiQPbCNpN4RdlrSMKyTJyJ/WYyIF65K wUehTkc2n269d4BNNgSAwbPtfEbrVG5IQh8SZoj4ddtC3iqW9QRv9WJa//oqRKdXmQMPVE 2RazBNhOi2DSq1PdSLPWKiqlUbj9ans= X-MC-Unique: 0cwx6LktN-OG7R4Ku81WOQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/5] virIndexToDiskName: Use g_string_prepend(_c) to improve readability Date: Wed, 3 Mar 2021 11:45:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.14 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use a dynamic string helper so that we don't have to calculate the string lenghts and then iterate from the rear. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virutil.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index 700ec02725..11e3e45615 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -432,24 +432,15 @@ int virDiskNameToIndex(const char *name) char *virIndexToDiskName(unsigned int idx, const char *prefix) { - char *name =3D NULL; - size_t i; - int ctr; - int offset; - - for (i =3D 0, ctr =3D idx; ctr >=3D 0; ++i, ctr =3D ctr / 26 - 1) { } - - offset =3D strlen(prefix); - - name =3D g_new0(char, offset + i + 1); + GString *str =3D g_string_new(NULL); + long long ctr; - strcpy(name, prefix); - name[offset + i] =3D '\0'; + for (ctr =3D idx; ctr >=3D 0; ctr =3D ctr / 26 - 1) + g_string_prepend_c(str, 'a' + (ctr % 26)); - for (i =3D i - 1, ctr =3D idx; ctr >=3D 0; --i, ctr =3D ctr / 26 - 1) - name[offset + i] =3D 'a' + (ctr % 26); + g_string_prepend(str, prefix); - return name; + return g_string_free(str, false); } #ifndef AI_CANONIDN --=20 2.29.2 From nobody Tue Apr 30 16:47:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1614768371; cv=none; d=zohomail.com; s=zohoarc; b=E7IQ9YrCjwVf3UkGjtF4WTQISBzI2ixYSG6JtG/p7nFE7WsQy+izy33PWqR6CQWWI4oAHDcwSFkAunEQtcfNOh/YkjZfIIB8IUfqsd27T+hbkxkx4HT0l3+6yqeaFHzUeYTTnJEijRneFjEBNm2Go9LhdCx8qyfhBKFybIRzAyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614768371; 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=z/Y413NUB7esD9gZC5mebazwA+djRgLykn7ud5bpiIk=; b=OJ5v1hYw6+2vMAKi1q2QnaqzHiqyNcpCTtXtlxqgpH9F7SnHg/J0bZquf9125tiVSEb6IzEMEcKRfrBQc2ZMXI+d9SJTGPi1uZDOHjYdFU8tl+HWBo5/w9Qh0GW/Id5nEIGZmJ4S5uQFhJ28It7phbssbxVFnGb9Q2qBJHhLXjk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614768371019274.9959181307273; Wed, 3 Mar 2021 02:46:11 -0800 (PST) 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-232-qEd-vb-6P8OVzw3rMQqLRA-1; Wed, 03 Mar 2021 05:46:07 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A4E01DE0A; Wed, 3 Mar 2021 10:46:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D336110013DB; Wed, 3 Mar 2021 10:46:01 +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 8C3691809C8F; Wed, 3 Mar 2021 10:46:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 123Ajj5h027940 for ; Wed, 3 Mar 2021 05:45:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 69C2869323; Wed, 3 Mar 2021 10:45:45 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C92215D768 for ; Wed, 3 Mar 2021 10:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614768370; 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=z/Y413NUB7esD9gZC5mebazwA+djRgLykn7ud5bpiIk=; b=BnYlw6Ule6WajRSXKhGAmId32O9CC/wwgRfU4KyU2hjtsETLJSPLMF34lEzk0mqb9hOiuy fK1KeTCZB85GWUvk/SU7Rkwdaixhv/GhoICDXG4P4vgFtBUReXXOjiC7IGa7cNWht3Hm2u Ctg70oPd8yFizIgoJF6i9Ow5O6HJD+8= X-MC-Unique: qEd-vb-6P8OVzw3rMQqLRA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/5] remote_daemon_dispatch: Replace g_new + strcpy with g_strdup Date: Wed, 3 Mar 2021 11:45:35 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/remote/remote_daemon_dispatch.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index e9f2a0ce5b..9700dba450 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -2647,8 +2647,7 @@ remoteDispatchDomainGetSecurityLabel(virNetServerPtr = server G_GNUC_UNUSED, goto cleanup; ret->label.label_len =3D strlen(seclabel->label) + 1; - ret->label.label_val =3D g_new0(char, ret->label.label_len); - strcpy(ret->label.label_val, seclabel->label); + ret->label.label_val =3D g_strdup(seclabel->label); ret->enforcing =3D seclabel->enforcing; rv =3D 0; @@ -2729,12 +2728,10 @@ remoteDispatchNodeGetSecurityModel(virNetServerPtr = server G_GNUC_UNUSED, goto cleanup; ret->model.model_len =3D strlen(secmodel.model) + 1; - ret->model.model_val =3D g_new0(char, ret->model.model_len); - strcpy(ret->model.model_val, secmodel.model); + ret->model.model_val =3D g_strdup(secmodel.model); ret->doi.doi_len =3D strlen(secmodel.doi) + 1; - ret->doi.doi_val =3D g_new0(char, ret->doi.doi_len); - strcpy(ret->doi.doi_val, secmodel.doi); + ret->doi.doi_val =3D g_strdup(secmodel.doi); rv =3D 0; --=20 2.29.2 From nobody Tue Apr 30 16:47:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1614768360; cv=none; d=zohomail.com; s=zohoarc; b=YOg5waCG8xgO1+F0jOa4Sf/7XxkOBztLoPADKBVJGnefGbMlYKwpM1Wm24LLhLzdUXo2jcC6hOE6dPBmcrwDEUqPtQbatuAk0KR2/eNeS2XBRR3HCni7ZcWySOC/5163YCIdnNLIoE1GVP9///hPW5fCYH5uoF3R5jisAmHEjZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614768360; 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=MgkPzXTLztIzvy1QLxJnp3+K3vdl2CCv5eHCMA98lCg=; b=ixGhPYe0UHNhPYqUA0oCa3wWLlgc0BxwhthVZFmZce5X43yvQc5OjnqECo87uFclsNCaiofKrABrUc7TOMBOfAFGs7VhribPdQdxZ45ubGGwl42W8QaEqvhlVFMy7E1/IjheUXD2QsbSD38xkuEX1Tj+R26Sey2HBiWItyyuQss= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614768360110362.21566328167785; Wed, 3 Mar 2021 02:46:00 -0800 (PST) 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-542-RPt443vWP8-ym9JSX5-iOA-1; Wed, 03 Mar 2021 05:45:56 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C0B51189C453; Wed, 3 Mar 2021 10:45:50 +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 8FF8419725; Wed, 3 Mar 2021 10:45:50 +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 31C0E5807B; Wed, 3 Mar 2021 10:45:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 123AjkBP027950 for ; Wed, 3 Mar 2021 05:45:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 74C6A5D74B; Wed, 3 Mar 2021 10:45:46 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C98485D768 for ; Wed, 3 Mar 2021 10:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614768359; 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=MgkPzXTLztIzvy1QLxJnp3+K3vdl2CCv5eHCMA98lCg=; b=HzuLCtgCIEJsS3wMyvPyHNUSrH12ctcjhe2YIDelI4cAf1yCq5zuNLOt1RHoWJVosNgpHc J1sTzQ7SnSzguBDg2DUrOwRyepIEBplcNKuCGLdpOnoVZj8Dlzlnv5ufn6OIorZvGUddhy D888iMX+Dp9TY5ZjB0QdvFmGSVIJZk4= X-MC-Unique: RPt443vWP8-ym9JSX5-iOA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/5] virHostCPUGetStatsLinux: Avoid 'strcpy' Date: Wed, 3 Mar 2021 11:45:36 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.23 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use an allocated buffer for 'cpu_header' so that g_strdup(_printf) can be used to fill it. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virhostcpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 4f6c3390ce..2446948bc1 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -787,7 +787,7 @@ virHostCPUGetStatsLinux(FILE *procstat, char line[1024]; unsigned long long usr, ni, sys, idle, iowait; unsigned long long irq, softirq, steal, guest, guest_nice; - char cpu_header[4 + VIR_INT64_STR_BUFLEN]; + g_autofree char *cpu_header =3D NULL; if ((*nparams) =3D=3D 0) { /* Current number of cpu stats supported by linux */ @@ -803,9 +803,9 @@ virHostCPUGetStatsLinux(FILE *procstat, } if (cpuNum =3D=3D VIR_NODE_CPU_STATS_ALL_CPUS) { - strcpy(cpu_header, "cpu "); + cpu_header =3D g_strdup("cpu "); } else { - g_snprintf(cpu_header, sizeof(cpu_header), "cpu%d ", cpuNum); + cpu_header =3D g_strdup_printf("cpu%d ", cpuNum); } while (fgets(line, sizeof(line), procstat) !=3D NULL) { --=20 2.29.2 From nobody Tue Apr 30 16:47:44 2024 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=1614768367; cv=none; d=zohomail.com; s=zohoarc; b=A7s3DcqOnR7T90mzJ/fH1thEReJlHu1cxVH7buGCgIQqrSG4c9LLIALUlPsie9ZMsjBJbrDv2QaFVKhXQUxGE6lTITMq+pqC+8BTGRIBTSY3n3MKQ98/f0Qc2Easzaqz+YSxsNPrSvs5mtsO3avbbNaaiZVIqjKtNCdUgRQiXHk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614768367; 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=A2nc4pFR9cvpParhrQFMpvf26szxEPZell7uRnivhrs=; b=IvnJQomr8mcvdSE5gekkGPHpKPEXODXhUyCPT7/Nl5QhBpdEts72D0GYhdh+S3LyWxaOp7LV38AUaTAmFfaul7KZwVNRhbXoFdQ1TRNV0qS1Jxdg3OhsONCV3PbxUAm/sy6ZNgHNNEeKsKh3s9DELdhOwBzwL6rujKnK7/odJNM= 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) header.from= 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 1614768367826987.4188787277818; Wed, 3 Mar 2021 02:46:07 -0800 (PST) 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-571-oomKGSDQPe-gkYuTcsV1bA-1; Wed, 03 Mar 2021 05:46:04 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD135DBC0; Wed, 3 Mar 2021 10:45:58 +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 BCAF46F45E; Wed, 3 Mar 2021 10:45:58 +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 868ED5807E; Wed, 3 Mar 2021 10:45:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 123AjlRO027969 for ; Wed, 3 Mar 2021 05:45:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 81BC55D74B; Wed, 3 Mar 2021 10:45:47 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFD0B62A03 for ; Wed, 3 Mar 2021 10:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614768366; 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=A2nc4pFR9cvpParhrQFMpvf26szxEPZell7uRnivhrs=; b=bngmhjYXzfqUX4WXKMbQUYj1brDfVBdrUcGshw+x2hqgFbGSSxkv7cTJcxamTqj6a3heHP vfh6ss6o4GWFmudUvYaVz8xTn9IjWZqmEmJCv6XlHrQa6BHcNoVfRjFvwIYhpOSikn3iA9 gi4F77IE7zDXPvKCMqZqLdRVVO12QcQ= X-MC-Unique: oomKGSDQPe-gkYuTcsV1bA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/5] commandhelper: printCwd: Print result directly instead of copying it Date: Wed, 3 Mar 2021 11:45:37 +0100 Message-Id: <27844d021b07670aa056190b2cd82076c300a0b0.1614768104.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.11 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- tests/commandhelper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index ee06339392..9b56feb120 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -221,9 +221,10 @@ static int printCwd(FILE *log) if (!(cwd =3D getcwd(NULL, 0))) return -1; - if ((strlen(cwd) > strlen(".../commanddata")) && - (STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata")= )) { - strcpy(cwd, ".../commanddata"); + if ((display =3D strstr(cwd, "/commanddata")) && + STREQ(display, "/commanddata")) { + fprintf(log, "CWD:.../commanddata\n"); + return 0; } display =3D cwd; --=20 2.29.2