From nobody Wed May 1 23:22:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1573578098; cv=none; d=zoho.com; s=zohoarc; b=NecufAXuoK6CsAf/5wTr2z8jB8JqKXoDPU5+w/WAEjbw0N53rArozKh7eUsOl8NfF0cNz80PuI2QAhMFw4pz5U/YjTK1YdXQg8470M05d0VAUI95WOW4Aez/UWrY5nIr+kv/24k5+1VqZyMKGGZNzwOibGsvRX26wsghOmEDv20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573578098; 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=wEdXsCPZwMIU+vcD4Q1uYrCQ6UEzZlCWpivPutflWMA=; b=bkqw14uFlsKKlnmtw1+Xud8Fu0yLB69ztSB1Fjj92SOy/RpiRVJeui8w8n9JS5ilHM6MHJdK+tIbOZJJMru/+1Zz4VaZc92T2mfV3y+/8YZVnOZ9bW8XAAp61507FI4IWHxS2BvkBbnxULi9gOuFjoexedZ3xmAFKFYuxdUYAvg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573578098389720.5786130202955; Tue, 12 Nov 2019 09:01:38 -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-322-8oq9Wm-OMzGxkaEg199o6A-1; Tue, 12 Nov 2019 12:01:35 -0500 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 8738118AAAE5; Tue, 12 Nov 2019 17:01:28 +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 2C35460BE0; Tue, 12 Nov 2019 17:01:28 +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 0853918034EE; Tue, 12 Nov 2019 17:01:27 +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 xACH1PHI012259 for ; Tue, 12 Nov 2019 12:01:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 41B9160173; Tue, 12 Nov 2019 17:01:25 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFD1060174 for ; Tue, 12 Nov 2019 17:01:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573578097; 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=wEdXsCPZwMIU+vcD4Q1uYrCQ6UEzZlCWpivPutflWMA=; b=Zje/j0coMrW0qfgZ0QfsjjPQ00xtWWIYYLY++Bd97N00bCMPIX4E8wMSqjg0kzZ6FkdMS/ x4TsGeh/JX4rbdsdj1v9dTi4ZwK8jrsHsgcO6DUkUOg62WAeHnaeDC5VlOXPlRdM2ZrKqe oCOp4WS4/RpVp/A+plhx3v4P0w6cogY= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 18:02:09 +0100 Message-Id: <32cff73d2a51c273608d73fe8ae7a6fe15232502.1573578043.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 Subject: [libvirt] [PATCH 1/9] Remove VIR_STRDUP usage that snuck in 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 X-MC-Unique: 8oq9Wm-OMzGxkaEg199o6A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Fixes: 224d269f19f0a6c496dd2218f934a54742d51708 Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_domain.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9c517597bb..ffac73dd42 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12835,8 +12835,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!usb) goto cleanup; =20 - if (VIR_STRDUP(tmpPath, virUSBDeviceGetPath(usb)) < 0) - goto cleanup; + tmpPath =3D g_strdup(virUSBDeviceGetPath(usb)); perm =3D VIR_CGROUP_DEVICE_RW; break; =20 @@ -12857,8 +12856,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!scsi) goto cleanup; =20 - if (VIR_STRDUP(tmpPath, virSCSIDeviceGetPath(scsi)) < 0) - goto cleanup; + tmpPath =3D g_strdup(virSCSIDeviceGetPath(scsi)); perm =3D virSCSIDeviceGetReadonly(scsi) ? VIR_CGROUP_DEVICE_READ : VIR_CGROUP_DEVICE_RW; } @@ -12870,8 +12868,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!(host =3D virSCSIVHostDeviceNew(hostsrc->wwpn))) goto cleanup; =20 - if (VIR_STRDUP(tmpPath, virSCSIVHostDeviceGetPath(host)) <= 0) - goto cleanup; + tmpPath =3D g_strdup(virSCSIVHostDeviceGetPath(host)); perm =3D VIR_CGROUP_DEVICE_RW; } break; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:22:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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=1573578108; cv=none; d=zoho.com; s=zohoarc; b=WkvWQV16StSOj/Em2+B3pl66AmJMjIxOIqLpdaLe0AX7nJ98FeCkvIaB2n/3J+2OLSk+1bLSEVtzVWUvk0IUBDnhlOT/IxUeD6CKw3FznPfZTGTENPLQXasrThzsoNlKP35fcuhnb8TxgWitWxyoc0emDufPOyc+XRIMxmf18BU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573578108; 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=SZ+xKL79FRFv8pHE86kpsXynt/hQT+7NBse3L3rZKaI=; b=nnJ61rXSb85mS8hpnWp8/3ZAhOQKuSDg/1sea4Z6JuJETfkjdePvCX4Q35DdbL+vf/d527UagUE/LeGSf99Re8avtS4NhjXru5JsoDW8glvaYgAhMR7hZVXsp2WAjbNIR4PpRBFARR4EmyLwjM0j3+ER/EtsXSE+5YcssJ/WWlY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 15735781082331021.6764118424363; Tue, 12 Nov 2019 09:01:48 -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-319-pixYYUqkOw2bsFplprlEKA-1; Tue, 12 Nov 2019 12:01:44 -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 B58B08E965B; Tue, 12 Nov 2019 17:01:38 +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 6B6405DE7C; Tue, 12 Nov 2019 17:01:38 +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 048E14E572; Tue, 12 Nov 2019 17:01:38 +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 xACH1QCh012269 for ; Tue, 12 Nov 2019 12:01:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1075960174; Tue, 12 Nov 2019 17:01:26 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EAEF60173 for ; Tue, 12 Nov 2019 17:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573578107; 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=SZ+xKL79FRFv8pHE86kpsXynt/hQT+7NBse3L3rZKaI=; b=HnchRvTCJtbm1fYRUzFAhmECz17uxQwDB6bUe6zBUMQsvteYkzNuqli5kziEgbUAahspQq vNDpIYGPlZwP5lhzE9bj17rNYD6Z3qTe+n15xDADIlOfkvIT+/6vsuSFiqbkhvrAVdcpkX HFejWThmuQOnmsWT2PBqYSwTFcE+1OQ= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 18:02:10 +0100 Message-Id: <6246562964bd0668a293ea63949390ac5d218675.1573578043.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 Subject: [libvirt] [PATCH 2/9] Remove VIR_STRNDUP usage that passes -1 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 X-MC-Unique: pixYYUqkOw2bsFplprlEKA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Replace all the usage of VIR_STRNDUP(dest, b, p ? p - b : -1) with separate calls to g_strndup/g_strdup. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza --- src/bhyve/bhyve_parse_command.c | 38 +++++++++++++++++++++------------ src/libxl/xen_common.c | 15 +++++++------ src/remote/remote_driver.c | 6 ++++-- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_comman= d.c index fa3b881f21..5c5dfae4a9 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -150,8 +150,10 @@ bhyveCommandLineToArgv(const char *nativeConfig, start =3D curr; next =3D strchr(curr, '\n'); =20 - if (VIR_STRNDUP(line, curr, next ? next - curr : -1) < 0) - goto error; + if (next) + line =3D g_strndup(curr, next - curr); + else + line =3D g_strdup(curr); =20 if (VIR_RESIZE_N(lines, lines_alloc, line_count, 2) < 0) { VIR_FREE(line); @@ -194,8 +196,10 @@ bhyveCommandLineToArgv(const char *nativeConfig, next =3D strchr(start, ' '); } =20 - if (VIR_STRNDUP(arg, curr, next ? next - curr : -1) < 0) - goto error; + if (next) + arg =3D g_strndup(curr, next - curr); + else + arg =3D g_strdup(curr); =20 if (next && (*next =3D=3D '\'' || *next =3D=3D '"')) next++; @@ -366,8 +370,10 @@ bhyveParsePCISlot(const char *slotdef, =20 next =3D strchr(curr, ':'); =20 - if (VIR_STRNDUP(val, curr, next? next - curr : -1) < 0) - goto error; + if (next) + val =3D g_strndup(curr, next - curr); + else + val =3D g_strdup(curr); =20 if (virStrToLong_ui(val, NULL, 10, &values[i]) < 0) goto error; @@ -441,9 +447,10 @@ bhyveParsePCIDisk(virDomainDefPtr def, goto error; =20 separator =3D strchr(config, ','); - if (VIR_STRNDUP(disk->src->path, config, - separator? separator - config : -1) < 0) - goto error; + if (separator) + disk->src->path =3D g_strndup(config, separator - config); + else + disk->src->path =3D g_strdup(config); =20 if (bus =3D=3D VIR_DOMAIN_DISK_BUS_VIRTIO) { idx =3D *nvirtiodisk; @@ -515,9 +522,10 @@ bhyveParsePCINet(virDomainDefPtr def, } =20 separator =3D strchr(config, ','); - if (VIR_STRNDUP(net->ifname, config, - separator? separator - config : -1) < 0) - goto error; + if (separator) + net->ifname =3D g_strndup(config, separator - config); + else + net->ifname =3D g_strdup(config); =20 if (!separator) goto cleanup; @@ -578,8 +586,10 @@ bhyveParseBhyvePCIArg(virDomainDefPtr def, if (conf) conf++; /* Skip initial comma */ =20 - if (VIR_STRNDUP(emulation, separator, conf? conf - separator - 1 : -1)= < 0) - goto error; + if (conf) + emulation =3D g_strndup(separator, conf - separator - 1); + else + emulation =3D g_strdup(separator); =20 if (bhyveParsePCISlot(slotdef, &pcislot, &bus, &function) < 0) goto error; diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index c31a5c952e..a4a9ec59bf 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -823,9 +823,11 @@ xenParseSxprChar(const char *value, =20 offset2 =3D strchr(offset, ','); offset++; - if (VIR_STRNDUP(def->source->data.tcp.service, offset, - offset2 ? offset2 - offset : -1) < 0) - goto error; + if (offset2) + def->source->data.tcp.service =3D g_strndup(offset, + offset2 - offset); + else + def->source->data.tcp.service =3D g_strdup(offset); =20 if (offset2 && strstr(offset2, ",server")) def->source->data.tcp.listen =3D true; @@ -875,9 +877,10 @@ xenParseSxprChar(const char *value, case VIR_DOMAIN_CHR_TYPE_UNIX: { const char *offset =3D strchr(value, ','); - if (VIR_STRNDUP(def->source->data.nix.path, value, - offset ? offset - value : -1) < 0) - goto error; + if (offset) + def->source->data.nix.path =3D g_strndup(value, offset - value= ); + else + def->source->data.nix.path =3D g_strdup(value); =20 if (offset !=3D NULL && strstr(offset, ",server") !=3D NULL) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 451a45f590..503f49a902 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -215,8 +215,10 @@ static int remoteSplitURIScheme(virURIPtr uri, =20 *driver =3D *transport =3D NULL; =20 - if (VIR_STRNDUP(*driver, uri->scheme, p ? p - uri->scheme : -1) < 0) - return -1; + if (p) + *driver =3D g_strndup(uri->scheme, p - uri->scheme); + else + *driver =3D g_strdup(uri->scheme); =20 if (p) { *transport =3D g_strdup(p + 1); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:22:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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=1573578101; cv=none; d=zoho.com; s=zohoarc; b=g4Hyu0LiPJB/XmeDIJm1BUfluDl7gZR/31XAR64HE1Xboxm1Es8iqNmZqxWXfnBscJQr+1wIPrUUYkQSutH1woLmH5jBzEfdY59zVEw4tdbj1lWhqnSPva2BaDZF32oNDesobBNlOjx7j/OwABmvzLPWFr41qbrN9IfAhgpE1KE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573578101; 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=ILDGOALyAufR6ANBi0FBTdGAzwnXJ4QaTozdLqSQdkE=; b=IdCZH3wQ7m/AAFsVAhe6FPGjWiI4UGgqlBy5IKMwKG5Rp0B0cqaBq/tP1THmBkLcwqSAdwIeFw3DvCyCOLEXCjJ+aUJrCO9DiC2RprJPCCjDhjhXYf10JWdzMHzTtP3VGFTqIUOqtXn0eGBynmWzsEn6rwJqgp2zYZq3x5BhmRQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1573578101476472.6467153941327; Tue, 12 Nov 2019 09:01:41 -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-297-13OCLpE7O-WhZc2qppAy2Q-1; Tue, 12 Nov 2019 12:01:36 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB51B10225BC; Tue, 12 Nov 2019 17:01:30 +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 9231058; Tue, 12 Nov 2019 17:01:30 +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 1B7C94E570; Tue, 12 Nov 2019 17:01:30 +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 xACH1R0Y012278 for ; Tue, 12 Nov 2019 12:01:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 08D1C60174; Tue, 12 Nov 2019 17:01:27 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5ED4760173 for ; Tue, 12 Nov 2019 17:01:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573578100; 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=ILDGOALyAufR6ANBi0FBTdGAzwnXJ4QaTozdLqSQdkE=; b=f3uoounhkc9/LFbnxXMtndeKwbubv+NA1xAh9HUij779IbJKfEDw6F/+AUsCgZhjUGkna1 faKZqgrP3hDec7Zj9Yw41aWe8O9Lz6kxW+T6ILTYNT2jJbAYB9xbD3vtE/cGg7l5lPzNM7 1kIC47VB32hVblqQBW8BB8PFakXVkzc= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 18:02:11 +0100 Message-Id: <6345b2e67bc8a7a6da1168666ebe9087f6dab397.1573578043.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 Subject: [libvirt] [PATCH 3/9] Remove VIR_STRNDUP usage that subtracts from a non-NULL pointer 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.15 X-MC-Unique: 13OCLpE7O-WhZc2qppAy2Q-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use g_strndup in all the cases where we check upfront whether a pointer is non-NULL and then use it to calculate the copied length. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza --- src/util/virsysinfo.c | 241 ++++++++++++++++++++---------------------- 1 file changed, 112 insertions(+), 129 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 9d013067fe..635e4c4bfb 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -220,23 +220,23 @@ virSysinfoParsePPCSystem(const char *base, virSysinfo= SystemDefPtr *sysdef) cur =3D strchr(cur, ':') + 1; eol =3D strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->family =3D g_strndup(cur, eol - cur); =20 if ((cur =3D strstr(base, "model")) !=3D NULL) { cur =3D strchr(cur, ':') + 1; eol =3D strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->serial =3D g_strndup(cur, eol - cur); } =20 if ((cur =3D strstr(base, "machine")) !=3D NULL) { cur =3D strchr(cur, ':') + 1; eol =3D strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->version =3D g_strndup(cur, eol - cur); } =20 if (!def->manufacturer && !def->product && !def->version && @@ -248,7 +248,6 @@ virSysinfoParsePPCSystem(const char *base, virSysinfoSy= stemDefPtr *sysdef) *sysdef =3D def; def =3D NULL; ret =3D 0; - cleanup: virSysinfoSystemDefFree(def); return ret; } @@ -270,18 +269,17 @@ virSysinfoParsePPCProcessor(const char *base, virSysi= nfoDefPtr ret) processor =3D &ret->processor[ret->nprocessor - 1]; =20 virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(processor->processor_socket_destination, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_socket_destination =3D g_strndup(cur, + eol - cur); base =3D cur; =20 if ((cur =3D strstr(base, "cpu")) !=3D NULL) { cur =3D strchr(cur, ':') + 1; eol =3D strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(processor->processor_type, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_type =3D g_strndup(cur, eol - cur); base =3D cur; } =20 @@ -289,9 +287,8 @@ virSysinfoParsePPCProcessor(const char *base, virSysinf= oDefPtr ret) cur =3D strchr(cur, ':') + 1; eol =3D strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(processor->processor_version, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_version =3D g_strndup(cur, eol - cur); base =3D cur; } =20 @@ -354,23 +351,23 @@ virSysinfoParseARMSystem(const char *base, virSysinfo= SystemDefPtr *sysdef) cur =3D strchr(cur, ':') + 1; eol =3D strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->family =3D g_strndup(cur, eol - cur); =20 if ((cur =3D strstr(base, "model")) !=3D NULL) { cur =3D strchr(cur, ':') + 1; eol =3D strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->serial =3D g_strndup(cur, eol - cur); } =20 if ((cur =3D strstr(base, "machine")) !=3D NULL) { cur =3D strchr(cur, ':') + 1; eol =3D strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->version =3D g_strndup(cur, eol - cur); } =20 if (!def->manufacturer && !def->product && !def->version && @@ -382,7 +379,6 @@ virSysinfoParseARMSystem(const char *base, virSysinfoSy= stemDefPtr *sysdef) *sysdef =3D def; def =3D NULL; ret =3D 0; - cleanup: virSysinfoSystemDefFree(def); return ret; } @@ -402,8 +398,8 @@ virSysinfoParseARMProcessor(const char *base, virSysinf= oDefPtr ret) eol =3D strchr(tmp_base, '\n'); cur =3D strchr(tmp_base, ':') + 1; virSkipSpaces(&cur); - if (eol && VIR_STRNDUP(processor_type, cur, eol - cur) < 0) - goto error; + if (eol) + processor_type =3D g_strndup(cur, eol - cur); =20 while ((tmp_base =3D strstr(base, "processor")) !=3D NULL) { base =3D tmp_base; @@ -415,10 +411,9 @@ virSysinfoParseARMProcessor(const char *base, virSysin= foDefPtr ret) processor =3D &ret->processor[ret->nprocessor - 1]; =20 virSkipSpaces(&cur); - if (eol && - VIR_STRNDUP(processor->processor_socket_destination, - cur, eol - cur) < 0) - goto error; + if (eol) + processor->processor_socket_destination =3D g_strndup(cur, + eol - cur); =20 processor->processor_type =3D g_strdup(processor_type); =20 @@ -670,29 +665,29 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSD= efPtr *bios) cur +=3D 8; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->vendor, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->vendor =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Version: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->version =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Release Date: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->date, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->date =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "BIOS Revision: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->release, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->release =3D g_strndup(cur, eol - cur); } =20 if (!def->vendor && !def->version && @@ -704,7 +699,6 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDef= Ptr *bios) *bios =3D def; def =3D NULL; ret =3D 0; - cleanup: virSysinfoBIOSDefFree(def); return ret; } @@ -728,50 +722,50 @@ virSysinfoParseX86System(const char *base, virSysinfo= SystemDefPtr *sysdef) cur +=3D 14; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->manufacturer =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Product Name: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->product =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Version: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->version =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Serial Number: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->serial =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "UUID: ")) !=3D NULL) { cur +=3D 6; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->uuid, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->uuid =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "SKU Number: ")) !=3D NULL) { cur +=3D 12; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->sku =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Family: ")) !=3D NULL) { cur +=3D 8; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->family =3D g_strndup(cur, eol - cur); } =20 if (!def->manufacturer && !def->product && !def->version && @@ -783,7 +777,6 @@ virSysinfoParseX86System(const char *base, virSysinfoSy= stemDefPtr *sysdef) *sysdef =3D def; def =3D NULL; ret =3D 0; - cleanup: virSysinfoSystemDefFree(def); return ret; } @@ -813,43 +806,43 @@ virSysinfoParseX86BaseBoard(const char *base, cur +=3D 14; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->manufacturer =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Product Name: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->product =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Version: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->version =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Serial Number: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->serial =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Asset Tag: ")) !=3D NULL) { cur +=3D 11; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->asset =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Location In Chassis: ")) !=3D NULL) { cur +=3D 21; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->location, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->location =3D g_strndup(cur, eol - cur); } =20 if (!def->manufacturer && !def->product && !def->version && @@ -898,36 +891,36 @@ virSysinfoParseX86Chassis(const char *base, cur +=3D 14; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->manufacturer =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Version: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->version =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Serial Number: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->serial =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Asset Tag: ")) !=3D NULL) { cur +=3D 11; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->asset =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "SKU Number: ")) !=3D NULL) { cur +=3D 12; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0) - goto cleanup; + if (eol) + def->sku =3D g_strndup(cur, eol - cur); } =20 if (!def->manufacturer && !def->version && @@ -939,7 +932,6 @@ virSysinfoParseX86Chassis(const char *base, *chassisdef =3D def; def =3D NULL; ret =3D 0; - cleanup: virSysinfoChassisDefFree(def); return ret; } @@ -964,86 +956,80 @@ virSysinfoParseX86Processor(const char *base, virSysi= nfoDefPtr ret) cur +=3D 20; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_socket_destination, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_socket_destination =3D g_strndup(cur, + eol - = cur); } if ((cur =3D strstr(base, "Type: ")) !=3D NULL) { cur +=3D 6; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_type, cur, eol - c= ur) < 0) - return -1; + if (eol) + processor->processor_type =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Family: ")) !=3D NULL) { cur +=3D 8; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_family, cur, eol -= cur) < 0) - return -1; + if (eol) + processor->processor_family =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Manufacturer: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_manufacturer, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_manufacturer =3D g_strndup(cur, eol -= cur); } if ((cur =3D strstr(base, "Signature: ")) !=3D NULL) { cur +=3D 11; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_signature, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_signature =3D g_strndup(cur, eol - cu= r); } if ((cur =3D strstr(base, "Version: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_version, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_version =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "External Clock: ")) !=3D NULL) { cur +=3D 16; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_external_clock, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_external_clock =3D g_strndup(cur, + eol - cur); } if ((cur =3D strstr(base, "Max Speed: ")) !=3D NULL) { cur +=3D 11; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_max_speed, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_max_speed =3D g_strndup(cur, eol - cu= r); } if ((cur =3D strstr(base, "Status: ")) !=3D NULL) { cur +=3D 8; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_status, cur, eol -= cur) < 0) - return -1; + if (eol) + processor->processor_status =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Serial Number: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_serial_number, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_serial_number =3D g_strndup(cur, eol = - cur); } if ((cur =3D strstr(base, "Part Number: ")) !=3D NULL) { cur +=3D 13; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(processor->processor_part_number, - cur, eol - cur) < 0) - return -1; + if (eol) + processor->processor_part_number =3D g_strndup(cur, eol - = cur); } =20 base +=3D strlen("Processor Information"); @@ -1074,74 +1060,71 @@ virSysinfoParseX86Memory(const char *base, virSysin= foDefPtr ret) goto next; =20 virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_size, cur, eol - cur) < = 0) - return -1; + if (eol) + memory->memory_size =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Form Factor: ")) !=3D NULL) { cur +=3D 13; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_form_factor, - cur, eol - cur) < 0) - return -1; + if (eol) + memory->memory_form_factor =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Locator: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_locator, cur, eol - cur)= < 0) - return -1; + if (eol) + memory->memory_locator =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Bank Locator: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_bank_locator, - cur, eol - cur) < 0) - return -1; + if (eol) + memory->memory_bank_locator =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Type: ")) !=3D NULL) { cur +=3D 6; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_type, cur, eol - cur) < = 0) - return -1; + if (eol) + memory->memory_type =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Type Detail: ")) !=3D NULL) { cur +=3D 13; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_type_detail, cur, eol - = cur) < 0) - return -1; + if (eol) + memory->memory_type_detail =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Speed: ")) !=3D NULL) { cur +=3D 7; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_speed, cur, eol - cur) <= 0) - return -1; + if (eol) + memory->memory_speed =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Manufacturer: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_manufacturer, cur, eol -= cur) < 0) - return -1; + if (eol) + memory->memory_manufacturer =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Serial Number: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_serial_number, - cur, eol - cur) < 0) - return -1; + if (eol) + memory->memory_serial_number =3D g_strndup(cur, eol - cur); } if ((cur =3D strstr(base, "Part Number: ")) !=3D NULL) { cur +=3D 13; eol =3D strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if (eol && VIR_STRNDUP(memory->memory_part_number, cur, eol - = cur) < 0) - return -1; + if (eol) + memory->memory_part_number =3D g_strndup(cur, eol - cur); } =20 next: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:22:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1573578107; cv=none; d=zoho.com; s=zohoarc; b=PQWCjosQVjlrcJPbW18eG8et4MtPDG7tpFZKp3smfpjtzN1TeNgmmxHVTamknG/V25ImGIegNM8JmuzZaxg7VhaEre7Ea0mMeozHEM4MMt4PYXaUa6fIMYG06yUHT+potgx+jmdIZWSK6w//c2APqR9jRs+O3BM3NFUisYjROus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573578107; 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=65VvTUH9p5zWmwIPMJIcoX5pP0ove6YvXvLB70TWTQI=; b=l3j5iMU3g/aFUXVpcKCHMbOnImtuxTXgjnAnzjxx2+TltF3rPwfDFwgvCiZPjpykPyEIIXAuSiz6hgt1+ZklNNrarPw6U8V6JOAAs2PS4FFHt+2+boQitxYUGQU0RSa4HpkK7mmB9KclaKgYgqD7S7p0mlswPCNxK4sUdTzwTDE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573578107181300.71260784016306; Tue, 12 Nov 2019 09:01:47 -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-330-B3sOCLd9PGae5o1cripfGg-1; Tue, 12 Nov 2019 12:01:44 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78AA78A2C55; Tue, 12 Nov 2019 17:01:38 +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 3A56618215; Tue, 12 Nov 2019 17:01:38 +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 B6CF118034F0; Tue, 12 Nov 2019 17:01:37 +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 xACH1RDq012290 for ; Tue, 12 Nov 2019 12:01:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id CB76260174; Tue, 12 Nov 2019 17:01:27 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5518F60173 for ; Tue, 12 Nov 2019 17:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573578105; 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=65VvTUH9p5zWmwIPMJIcoX5pP0ove6YvXvLB70TWTQI=; b=ZMzM301olrO+umckdZdEtIdMHYFTxVBJQm0UqhCblu0GbdhC/DNGgnWEytuV78XLpxCdM6 eG76vCO0O25CqMa2/ZsVmB20A+NadMTFAtkFhbn/Rgqf65+N+kCAuryI2UCVwWo8EkvfF1 bsFti6wwven3ppjhjbvDRcPKA85hQv0= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 18:02:12 +0100 Message-Id: <2348d477a1fcc32b4600b00e76d2b601a6ae8ed2.1573578043.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 Subject: [libvirt] [PATCH 4/9] Remove VIR_STRNDUP usage with checked pointers 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.16 X-MC-Unique: B3sOCLd9PGae5o1cripfGg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Remove the usage where sanity of the length argument is verified by other conditions not matching the previous patches. Signed-off-by: J=C3=A1n Tomko --- src/libxl/xen_common.c | 18 ++++++++---------- tools/vsh.c | 5 ++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index a4a9ec59bf..7ac24fb606 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -817,9 +817,8 @@ xenParseSxprChar(const char *value, goto error; } =20 - if (offset !=3D value && - VIR_STRNDUP(def->source->data.tcp.host, value, offset - value)= < 0) - goto error; + if (offset !=3D value) + def->source->data.tcp.host =3D g_strndup(value, offset - value= ); =20 offset2 =3D strchr(offset, ','); offset++; @@ -845,9 +844,9 @@ xenParseSxprChar(const char *value, goto error; } =20 - if (offset !=3D value && - VIR_STRNDUP(def->source->data.udp.connectHost, value, offset -= value) < 0) - goto error; + if (offset !=3D value) + def->source->data.udp.connectHost =3D g_strndup(value, + offset - value); =20 offset2 =3D strchr(offset, '@'); if (offset2 !=3D NULL) { @@ -862,10 +861,9 @@ xenParseSxprChar(const char *value, goto error; } =20 - if (offset3 > (offset2 + 1) && - VIR_STRNDUP(def->source->data.udp.bindHost, - offset2 + 1, offset3 - offset2 - 1) < 0) - goto error; + if (offset3 > (offset2 + 1)) + def->source->data.udp.bindHost =3D g_strndup(offset2 + 1, + offset3 - offse= t2 - 1); =20 def->source->data.udp.bindService =3D g_strdup(offset3 + 1); } else { diff --git a/tools/vsh.c b/tools/vsh.c index 000cf6a009..2b1e0506ba 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -360,9 +360,8 @@ vshCmddefCheckInternals(vshControl *ctl, cmd->name); return -1; /* alias options are tracked by the original na= me */ } - if ((p =3D strchr(name, '=3D')) && - VIR_STRNDUP(name, name, p - name) < 0) - vshErrorOOM(); + if ((p =3D strchr(name, '=3D'))) + name =3D g_strndup(name, p - name); 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) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:22:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1573578113; cv=none; d=zoho.com; s=zohoarc; b=nJoTPJ8sqLL8Rz6e5kkcJI7jRECWrimvqVQPT1c29S/XOMGKRkkWzWGIyRJYYrME74goVvGRXS/KVxeay8qaMntMVXXevr3uVR57puV9FhioOoNjRLuULdIkkAL+7CXAnLC2CPyry3sRLAA7GY/DzpJ9ObKpJjPua91gZp1JEdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573578113; 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=7fOeIoTS2nxDSHsBE13NTCmHuaeRythUVqLzaXocdQ0=; b=JXkxGyT1vceM3fx7n9Ct2zn0nMZGuxMvloRu0wcJhOQKSOj5lXc5nexIE7evvwkfJpVb2ouRCF9kUKtT2wUpAyo13Th84wcjbJq7NTo1OQWysfvJ87DfrM5HiOlXLB3H/DGXhl+ku8rZpueB+cYN74Z1Fk2m6clZLiuXYinD4Kw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1573578113270145.6582575478942; Tue, 12 Nov 2019 09:01:53 -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-342-ny2f3KnTPb6gF6fvYIIFUA-1; Tue, 12 Nov 2019 12:01:49 -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 B81E88F0366; Tue, 12 Nov 2019 17:01:38 +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 77A66600D5; Tue, 12 Nov 2019 17:01:38 +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 05B4418034E9; Tue, 12 Nov 2019 17:01:38 +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 xACH1Svm012295 for ; Tue, 12 Nov 2019 12:01:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id A1C9760174; Tue, 12 Nov 2019 17:01:28 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2634D60173 for ; Tue, 12 Nov 2019 17:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573578112; 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=7fOeIoTS2nxDSHsBE13NTCmHuaeRythUVqLzaXocdQ0=; b=UcCTy6i2wEMMEhTQYvKOQJt5FXT5hpaNuv/AYSqqiscYXKZo2Ia/pySgXCfs0KKGFeKRA4 eT9UC6mBtXTjSjUscHFn+k5fmM5GMO5iqJDKQDZFfPWuaEuf8LOyS2WczDC28oaej920Qg jpvoREUhZYgppGpcyU95iveCz99Eszo= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 18:02:13 +0100 Message-Id: <59577bf7a7a6554060042203d54e770bc7a32228.1573578043.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 Subject: [libvirt] [PATCH 5/9] Remove VIR_STRNDUP usage with subtraction 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 X-MC-Unique: ny2f3KnTPb6gF6fvYIIFUA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Remove all the uses that use subtraction in their length argument. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza --- src/bhyve/bhyve_parse_command.c | 6 ++---- src/libxl/xen_common.c | 8 +++----- src/libxl/xen_xm.c | 3 +-- src/lxc/lxc_driver.c | 3 +-- src/qemu/qemu_driver.c | 3 +-- src/qemu/qemu_monitor_json.c | 8 ++------ src/util/vircgroupv1.c | 5 ++--- src/util/vircommand.c | 5 ++--- src/util/virconf.c | 24 +++++++----------------- src/util/virkeyfile.c | 6 ++---- src/util/virstoragefile.c | 3 +-- src/util/virstring.c | 4 +--- src/util/virsysinfo.c | 3 +-- src/vmware/vmware_conf.c | 6 +----- 14 files changed, 27 insertions(+), 60 deletions(-) diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_comman= d.c index 5c5dfae4a9..93c9c10b39 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -283,8 +283,7 @@ bhyveParseBhyveLPCArg(virDomainDefPtr def, if (!separator) goto error; =20 - if (VIR_STRNDUP(type, arg, separator - arg) < 0) - goto error; + type =3D g_strndup(arg, separator - arg); =20 /* Only support com%d */ if (STRPREFIX(type, "com") && type[4] =3D=3D 0) { @@ -579,8 +578,7 @@ bhyveParseBhyvePCIArg(virDomainDefPtr def, else separator++; /* Skip comma */ =20 - if (VIR_STRNDUP(slotdef, arg, separator - arg - 1) < 0) - goto error; + slotdef =3D g_strndup(arg, separator - arg - 1); =20 conf =3D strchr(separator+1, ','); if (conf) diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 7ac24fb606..e6d022f253 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -850,9 +850,8 @@ xenParseSxprChar(const char *value, =20 offset2 =3D strchr(offset, '@'); if (offset2 !=3D NULL) { - if (VIR_STRNDUP(def->source->data.udp.connectService, - offset + 1, offset2 - offset - 1) < 0) - goto error; + def->source->data.udp.connectService =3D g_strndup(offset + 1, + offset2 - off= set - 1); =20 offset3 =3D strchr(offset2, ':'); if (offset3 =3D=3D NULL) { @@ -994,8 +993,7 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridge) =20 if ((vlanstr =3D strchr(bridge, '.'))) { /* 'bridge' string contains a bridge name and single vlan tag */ - if (VIR_STRNDUP(net->data.bridge.brname, bridge, vlanstr - bridge)= < 0) - return -1; + net->data.bridge.brname =3D g_strndup(bridge, vlanstr - bridge); =20 vlanstr++; if (virStrToLong_ui(vlanstr, NULL, 10, &tag) < 0) diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 88cf9ac5b0..a0e649f4ef 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -131,8 +131,7 @@ xenParseXMDisk(char *entry, int hvm) /* No source file given, eg CDROM with no media */ ignore_value(virDomainDiskSetSource(disk, NULL)); } else { - if (VIR_STRNDUP(tmp, head, offset - head) < 0) - goto error; + tmp =3D g_strndup(head, offset - head); =20 if (virDomainDiskSetSource(disk, tmp) < 0) { VIR_FREE(tmp); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index ea86451b09..ef3649800b 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2150,8 +2150,7 @@ lxcDomainParseBlkioDeviceStr(char *blkioDeviceStr, co= nst char *type, if (!p) goto parse_error; =20 - if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) - goto cleanup; + result[i].path =3D g_strndup(temp, p - temp); =20 /* value */ temp =3D p + 1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f4ff2ba292..9e26af8af7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9289,8 +9289,7 @@ qemuDomainParseBlkioDeviceStr(char *blkioDeviceStr, c= onst char *type, if (!p) goto parse_error; =20 - if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) - goto cleanup; + result[i].path =3D g_strndup(temp, p - temp); =20 /* value */ temp =3D p + 1; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 10f6a4cadc..963ca58f43 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -644,15 +644,11 @@ qemuMonitorJSONParseKeywords(const char *str, separator =3D endmark; } =20 - if (VIR_STRNDUP(keyword, start, separator - start) < 0) - goto error; + keyword =3D g_strndup(start, separator - start); =20 if (separator < endmark) { separator++; - if (VIR_STRNDUP(value, separator, endmark - separator) < 0) { - VIR_FREE(keyword); - goto error; - } + value =3D g_strndup(separator, endmark - separator); if (strchr(value, ',')) { char *p =3D strchr(value, ',') + 1; char *q =3D p + 1; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index c1083b6d18..c0b6aa8204 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -769,9 +769,8 @@ virCgroupV1IdentifyRoot(virCgroupPtr group) return NULL; } =20 - if (VIR_STRNDUP(ret, group->legacy[i].mountPoint, - tmp - group->legacy[i].mountPoint) < 0) - return NULL; + ret =3D g_strndup(group->legacy[i].mountPoint, + tmp - group->legacy[i].mountPoint); return ret; } =20 diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 49432ddfcb..0993d3e168 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -3145,9 +3145,8 @@ virCommandRunRegex(virCommandPtr cmd, =20 /* NB vars[0] is the full pattern, so we offset j by 1 */ for (j =3D 1; j <=3D nvars[i]; j++) { - if (VIR_STRNDUP(groups[ngroup++], p + vars[j].rm_so, - vars[j].rm_eo - vars[j].rm_so) < 0) - goto cleanup; + groups[ngroup++] =3D g_strndup(p + vars[j].rm_so, + vars[j].rm_eo - vars[j].rm_so= ); } =20 } diff --git a/src/util/virconf.c b/src/util/virconf.c index cc88000387..4a16037284 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -386,8 +386,7 @@ virConfParseString(virConfParserCtxtPtr ctxt) virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string= ")); return NULL; } - if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) - return NULL; + ret =3D g_strndup(base, ctxt->cur - base); NEXT; } else if ((ctxt->cur + 6 < ctxt->end) && (STRPREFIX(ctxt->cur, "\"\"\""))) { @@ -407,8 +406,7 @@ virConfParseString(virConfParserCtxtPtr ctxt) virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string= ")); return NULL; } - if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) - return NULL; + ret =3D g_strndup(base, ctxt->cur - base); ctxt->cur +=3D 3; } else if (CUR =3D=3D '"') { NEXT; @@ -419,8 +417,7 @@ virConfParseString(virConfParserCtxtPtr ctxt) virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string= ")); return NULL; } - if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) - return NULL; + ret =3D g_strndup(base, ctxt->cur - base); NEXT; } else if (ctxt->conf->flags & VIR_CONF_FLAG_LXC_FORMAT) { base =3D ctxt->cur; @@ -430,8 +427,7 @@ virConfParseString(virConfParserCtxtPtr ctxt) /* Reverse to exclude the trailing blanks from the value */ while ((ctxt->cur > base) && (c_isblank(CUR))) ctxt->cur--; - if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) - return NULL; + ret =3D g_strndup(base, ctxt->cur - base); } return ret; } @@ -567,8 +563,7 @@ virConfParseName(virConfParserCtxtPtr ctxt) ((ctxt->conf->flags & VIR_CONF_FLAG_LXC_FORMAT) && (CUR =3D=3D '.')))) NEXT; - if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) - return NULL; + ret =3D g_strndup(base, ctxt->cur - base); return ret; } =20 @@ -591,8 +586,7 @@ virConfParseComment(virConfParserCtxtPtr ctxt) NEXT; base =3D ctxt->cur; while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT; - if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0) - return -1; + comm =3D g_strndup(base, ctxt->cur - base); if (virConfAddEntry(ctxt->conf, NULL, NULL, comm) =3D=3D NULL) { VIR_FREE(comm); return -1; @@ -666,11 +660,7 @@ virConfParseStatement(virConfParserCtxtPtr ctxt) NEXT; base =3D ctxt->cur; while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT; - if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0) { - VIR_FREE(name); - virConfFreeValue(value); - return -1; - } + comm =3D g_strndup(base, ctxt->cur - base); } if (virConfAddEntry(ctxt->conf, name, value, comm) =3D=3D NULL) { VIR_FREE(name); diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c index c7e756d26a..c5af85e72b 100644 --- a/src/util/virkeyfile.c +++ b/src/util/virkeyfile.c @@ -116,8 +116,7 @@ static int virKeyFileParseGroup(virKeyFileParserCtxtPtr= ctxt) return -1; } =20 - if (VIR_STRNDUP(ctxt->groupname, name, ctxt->cur - name) < 0) - return -1; + ctxt->groupname =3D g_strndup(name, ctxt->cur - name); =20 NEXT; =20 @@ -160,8 +159,7 @@ static int virKeyFileParseValue(virKeyFileParserCtxtPtr= ctxt) return -1; } =20 - if (VIR_STRNDUP(key, keystart, ctxt->cur - keystart) < 0) - return -1; + key =3D g_strndup(keystart, ctxt->cur - keystart); =20 NEXT; valuestart =3D ctxt->cur; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 77f885ef1d..a6ef64f73d 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2946,8 +2946,7 @@ virStorageSourceParseBackingColon(virStorageSourcePtr= src, return -1; } =20 - if (VIR_STRNDUP(protocol, path, p - path) < 0) - return -1; + protocol =3D g_strndup(path, p - path); =20 if ((src->protocol =3D virStorageNetProtocolTypeFromString(protocol)) = < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/util/virstring.c b/src/util/virstring.c index 283cf8c8d8..1b0b5dae97 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1058,9 +1058,7 @@ virStringSearch(const char *str, if (VIR_EXPAND_N(*matches, nmatches, 1) < 0) goto cleanup; =20 - if (VIR_STRNDUP(match, str + rem.rm_so, - rem.rm_eo - rem.rm_so) < 0) - goto cleanup; + match =3D g_strndup(str + rem.rm_so, rem.rm_eo - rem.rm_so); =20 VIR_DEBUG("Got '%s'", match); =20 diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 635e4c4bfb..fe43dfdd75 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -485,8 +485,7 @@ virSysinfoParseS390Delimited(const char *base, const ch= ar *name, char **value, start +=3D 1; end =3D strchrnul(start, delim2); virSkipSpaces(&start); - if (VIR_STRNDUP(*value, start, end - start) < 0) - return NULL; + *value =3D g_strndup(start, end - start); virTrimSpaces(*value, NULL); return end; } diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index ef7696a496..6b2c8888ab 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -348,8 +348,7 @@ vmwareParsePath(const char *path, char **directory, cha= r **filename) return -1; } =20 - if (VIR_STRNDUP(*directory, path, separator - path - 1) < 0) - goto error; + *directory =3D g_strndup(path, separator - path - 1); *filename =3D g_strdup(separator); =20 } else { @@ -357,9 +356,6 @@ vmwareParsePath(const char *path, char **directory, cha= r **filename) } =20 return 0; - - error: - return -1; } =20 void --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:22:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1573578118; cv=none; d=zoho.com; s=zohoarc; b=H21NdGBAJpr+r7gG0+/I/8HlyMTYh5+6o8kd537KBzo7eqw7KdYmsfJE0ZpHQJNX0qRYx9XLO8XtsDspIgrTR/vGOi8pWy24gJhBt07alICx9FFb6vB6gHUzv4NTMd34ZVSm2lfrRuX1IdEyJzKl+xy9XJlXvQtFoD2arvkGpp8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573578118; 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=p5H2/5bYJaP+UNQMfU+IZdG9onO444NyqTcIceciXMc=; b=V8dgQJ97jFy+N/NRKoaX4piDyBhWkZU8HLzo18iUtI+d9X5v02GgIpykAWeORrIV+wR50SMXDPxRY0NiC4PFiq+Q3lM27s2zC4zU0oqRGHx7DbL26ghjJg96PpLJY7OCJCIgdzKr0cU2C4hSztbkGgQB84tjxZKPI8CgMT6Sw/8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1573578118099606.2384388799727; Tue, 12 Nov 2019 09:01: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-180-UmOO_JrDPneRPBX1mfMEog-1; Tue, 12 Nov 2019 12:01:55 -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 7D3BC109D0D3; Tue, 12 Nov 2019 17:01:45 +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 4C9F0600D5; Tue, 12 Nov 2019 17:01:45 +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 EAFB24E573; Tue, 12 Nov 2019 17:01:44 +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 xACH1WxP012317 for ; Tue, 12 Nov 2019 12:01:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id F203960173; Tue, 12 Nov 2019 17:01:31 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A49B60174 for ; Tue, 12 Nov 2019 17:01:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573578116; 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=p5H2/5bYJaP+UNQMfU+IZdG9onO444NyqTcIceciXMc=; b=a0gbZp4gacKrWUQuVc/8MSak6VW1aaCqsj9bzoTFKAJxHFMVuJr0VpHkxTcCx0RNEu7cLU DF/QHo6VZFgJtkA4Y0yjHHjllSedZdnu5qwZQkh+nbX4MtYMPUzUP7/NVEmfRt/z+zZPde 1ct1NvVW08mShVGLpx41jzGY28PAcSc= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 18:02:14 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 6/9] Remove the rest of VIR_STRNDUP 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 X-MC-Unique: UmOO_JrDPneRPBX1mfMEog-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Replace all the uses passing a single parameter as the length. Signed-off-by: J=C3=A1n Tomko --- src/conf/nwfilter_conf.c | 4 ++-- src/conf/nwfilter_params.c | 6 ++---- src/interface/interface_backend_udev.c | 8 ++------ src/libxl/xen_common.c | 3 +-- src/libxl/xen_xl.c | 6 ++---- src/libxl/xen_xm.c | 6 ++---- src/qemu/qemu_monitor_json.c | 3 +-- src/rpc/virnetlibsshsession.c | 7 ++----- src/storage/storage_backend_logical.c | 7 ++----- src/util/viriscsi.c | 3 +-- src/util/virjson.c | 11 +++-------- src/util/virkeyfile.c | 3 +-- src/util/virsocketaddr.c | 5 +---- src/util/virstoragefile.c | 3 +-- src/util/virstring.c | 3 +-- 15 files changed, 24 insertions(+), 54 deletions(-) diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 6c7b85d4c8..7a4be5d4ec 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -401,8 +401,8 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf, { char *tmp; =20 - if (VIR_STRNDUP(tmp, string, maxstrlen) < 0 || - VIR_APPEND_ELEMENT_COPY(nwf->strings, nwf->nstrings, tmp) < 0) + tmp =3D g_strndup(string, maxstrlen); + if (VIR_APPEND_ELEMENT_COPY(nwf->strings, nwf->nstrings, tmp) < 0) VIR_FREE(tmp); =20 return tmp; diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 7608d4960e..4549b7a71c 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -884,8 +884,7 @@ virNWFilterVarAccessParse(const char *varAccess) =20 if (input[idx] =3D=3D '\0') { /* in the form 'IP', which is equivalent to IP[@0] */ - if (VIR_STRNDUP(dest->varName, input, idx) < 0) - goto err_exit; + dest->varName =3D g_strndup(input, idx); dest->accessType =3D VIR_NWFILTER_VAR_ACCESS_ITERATOR; dest->u.iterId =3D 0; return dest; @@ -898,8 +897,7 @@ virNWFilterVarAccessParse(const char *varAccess) =20 varNameLen =3D idx; =20 - if (VIR_STRNDUP(dest->varName, input, varNameLen) < 0) - goto err_exit; + dest->varName =3D g_strndup(input, varNameLen); =20 input +=3D idx + 1; virSkipSpaces(&input); diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index b7b06ed67a..531f9e90e5 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -954,12 +954,8 @@ udevGetIfaceDefVlan(struct udev *udev G_GNUC_UNUSED, goto cleanup; } =20 - if (VIR_STRNDUP(ifacedef->data.vlan.tag, vid_pos, vid_len) < 0) - goto cleanup; - if (VIR_STRNDUP(ifacedef->data.vlan.dev_name, dev_pos, dev_len) < 0) { - VIR_FREE(ifacedef->data.vlan.tag); - goto cleanup; - } + ifacedef->data.vlan.tag =3D g_strndup(vid_pos, vid_len); + ifacedef->data.vlan.dev_name =3D g_strndup(dev_pos, dev_len); =20 ret =3D 0; =20 diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index e6d022f253..66e7850245 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -1164,8 +1164,7 @@ xenParseVif(char *entry, const char *vif_typename) } else if (STRPREFIX(key, "script=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); VIR_FREE(script); - if (VIR_STRNDUP(script, data, len) < 0) - return NULL; + script =3D g_strndup(data, len); } else if (STRPREFIX(key, "model=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); if (virStrncpy(model, data, len, sizeof(model)) < 0) { diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 396adf6dac..4e2bdb2ed0 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1109,13 +1109,11 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr = def) } else if (STRPREFIX(key, "name=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); VIR_FREE(name); - if (VIR_STRNDUP(name, data, len) < 0) - goto cleanup; + name =3D g_strndup(data, len); } else if (STRPREFIX(key, "path=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); VIR_FREE(path); - if (VIR_STRNDUP(path, data, len) < 0) - goto cleanup; + path =3D g_strndup(data, len); } =20 while (nextkey && (nextkey[0] =3D=3D ',' || diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index a0e649f4ef..7dea2998f2 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -167,8 +167,7 @@ xenParseXMDisk(char *entry, int hvm) /* The main type phy:, file:, tap: ... */ if ((tmp =3D strchr(src, ':')) !=3D NULL) { len =3D tmp - src; - if (VIR_STRNDUP(tmp, src, len) < 0) - goto error; + tmp =3D g_strndup(src, len); =20 if (virDomainDiskSetDriver(disk, tmp) < 0) { VIR_FREE(tmp); @@ -192,8 +191,7 @@ xenParseXMDisk(char *entry, int hvm) goto error; len =3D tmp - src; =20 - if (VIR_STRNDUP(driverType, src, len) < 0) - goto error; + driverType =3D g_strndup(src, len); =20 if (STREQ(driverType, "aio")) virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 963ca58f43..aa2598a85d 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -272,8 +272,7 @@ int qemuMonitorJSONIOProcess(qemuMonitorPtr mon, if (nl) { int got =3D nl - (data + used); char *line; - if (VIR_STRNDUP(line, data + used, got) < 0) - return -1; + line =3D g_strndup(data + used, got); used +=3D got + strlen(LINE_ENDING); line[got] =3D '\0'; /* kill \n */ if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) { diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 2312939cdc..e874929740 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -431,9 +431,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt, goto error; } =20 - if (VIR_STRNDUP(actual_prompt, prompt, - virLengthForPromptString(prompt)) < 0) - goto error; + actual_prompt =3D g_strndup(prompt, virLengthForPromptString(prompt)); =20 memset(&retr_passphrase, 0, sizeof(virConnectCredential)); retr_passphrase.type =3D cred_type; @@ -716,8 +714,7 @@ virNetLibsshAuthenticateKeyboardInteractive(virNetLibss= hSessionPtr sess, =20 prompt =3D virBufferContentAndReset(&prompt_buff); } else { - if (VIR_STRNDUP(prompt, promptStr, promptStrLen) < 0) - goto prompt_error; + prompt =3D g_strndup(promptStr, promptStrLen); } =20 memset(&retr_passphrase, 0, sizeof(virConnectCredential)); diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 48023abd1a..ba3c5ea70e 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -214,13 +214,10 @@ virStorageBackendLogicalParseVolExtents(virStorageVol= DefPtr vol, len =3D vars[j].rm_eo - vars[j].rm_so; p[vars[j].rm_eo] =3D '\0'; =20 - if (VIR_STRNDUP(extent.path, - p + vars[j].rm_so, len) < 0) - goto cleanup; + extent.path =3D g_strndup(p + vars[j].rm_so, len); =20 len =3D vars[j + 1].rm_eo - vars[j + 1].rm_so; - if (VIR_STRNDUP(offset_str, p + vars[j + 1].rm_so, len) < 0) - goto cleanup; + offset_str =3D g_strndup(p + vars[j + 1].rm_so, len); =20 if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 9f4c8f4e03..84fa542b7c 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -162,8 +162,7 @@ virStorageBackendIQNFound(const char *initiatoriqn, if (!(next =3D strchr(current, ' '))) goto error; =20 - if (VIR_STRNDUP(iface, current, (next - current)) < 0) - goto cleanup; + iface =3D g_strndup(current, (next - current)); =20 current =3D next + 1; =20 diff --git a/src/util/virjson.c b/src/util/virjson.c index 76efb17e24..184d082dc5 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -463,10 +463,7 @@ virJSONValueNewStringLen(const char *data, return NULL; =20 val->type =3D VIR_JSON_TYPE_STRING; - if (VIR_STRNDUP(val->data.string, data, length) < 0) { - VIR_FREE(val); - return NULL; - } + val->data.string =3D g_strndup(data, length); =20 return val; } @@ -1633,8 +1630,7 @@ virJSONParserHandleNumber(void *ctx, char *str; virJSONValuePtr value; =20 - if (VIR_STRNDUP(str, s, l) < 0) - return -1; + str =3D g_strndup(s, l); value =3D virJSONValueNewNumber(str); VIR_FREE(str); =20 @@ -1691,8 +1687,7 @@ virJSONParserHandleMapKey(void *ctx, state =3D &parser->state[parser->nstate-1]; if (state->key) return 0; - if (VIR_STRNDUP(state->key, (const char *)stringVal, stringLen) < 0) - return 0; + state->key =3D g_strndup((const char *)stringVal, stringLen); return 1; } =20 diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c index c5af85e72b..998ce9caf7 100644 --- a/src/util/virkeyfile.c +++ b/src/util/virkeyfile.c @@ -172,8 +172,7 @@ static int virKeyFileParseValue(virKeyFileParserCtxtPtr= ctxt) len =3D ctxt->cur - valuestart; if (IS_EOF && !IS_EOL(CUR)) len++; - if (VIR_STRNDUP(value, valuestart, len) < 0) - goto cleanup; + value =3D g_strndup(valuestart, len); =20 if (virHashAddEntry(ctxt->group, key, value) < 0) { VIR_FREE(value); diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index d7b0f12d96..ef51d3fa7d 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -593,10 +593,7 @@ virSocketAddrGetPath(virSocketAddrPtr addr G_GNUC_UNUS= ED) return NULL; } =20 - if (VIR_STRNDUP(path, - addr->data.un.sun_path, - sizeof(addr->data.un.sun_path)) < 0) - return NULL; + path =3D g_strndup(addr->data.un.sun_path, sizeof(addr->data.un.sun_pa= th)); =20 return path; #else diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index a6ef64f73d..8c99c349a6 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -421,8 +421,7 @@ cowGetBackingStore(char **res, return BACKING_STORE_OK; } =20 - if (VIR_STRNDUP(*res, (const char*)buf + 4 + 4, COW_FILENAME_MAXLEN) <= 0) - return BACKING_STORE_ERROR; + *res =3D g_strndup((const char *)buf + 4 + 4, COW_FILENAME_MAXLEN); return BACKING_STORE_OK; } =20 diff --git a/src/util/virstring.c b/src/util/virstring.c index 1b0b5dae97..cd4418d144 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -91,8 +91,7 @@ virStringSplitCount(const char *string, if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) goto error; =20 - if (VIR_STRNDUP(tokens[ntokens], remainder, len) < 0) - goto error; + tokens[ntokens] =3D g_strndup(remainder, len); ntokens++; remainder =3D tmp + delimlen; tmp =3D strstr(remainder, delim); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:22:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1573578125; cv=none; d=zoho.com; s=zohoarc; b=aTosi1P7CPkEMyBAenAcz1jyn554MIxl9YvV/mfEt1UtRcK3H2dm55RyMhJDJkbSENBBHS7JqYOJ83h8+rpUmbwySN0Uc4RHt8l9eKnSQOtZt+3wVJNRXscKVzCfEGWtD2H8kJ2S12pJ8MggoGSHEssyrrVdApsOCxIH5yYELLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573578125; 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=eJOGkjVlOEAkgVsAX/7HiVKsyMU8nNEap7YcHfb5Nuo=; b=YJ80kNfLFkTX1HSBMbRWNxudR+tIqGe93xeEOkHF63E6ATfYjkuBER97JtbPoIbNquwLkFjPmsUvsm610B/oW1ZrWi+/sF83FsUP2/x/YVcfCXK2vBuG+PqL62NwL1rLoS7i0mUgPwD/tlseicIXpGYfGFThnnqhRZP4Co8CQQI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573578125240826.1163546536508; Tue, 12 Nov 2019 09:02:05 -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-34-NGOOwoEaNFqu-q_eaI7j1w-1; Tue, 12 Nov 2019 12:02:00 -0500 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 4C7B6B0242; Tue, 12 Nov 2019 17:01: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 0E7FEBA4E; Tue, 12 Nov 2019 17:01: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 A1AB44E57F; Tue, 12 Nov 2019 17:01:49 +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 xACH1WXB012323 for ; Tue, 12 Nov 2019 12:01:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id C28E7600D5; Tue, 12 Nov 2019 17:01:32 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49D3060173 for ; Tue, 12 Nov 2019 17:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573578124; 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=eJOGkjVlOEAkgVsAX/7HiVKsyMU8nNEap7YcHfb5Nuo=; b=OO8uHEk0JLL6iZJwLC4L73+q0HXwo527Hm126cOseJoZoHljGVJa38d5A8yEaQaGGbndq6 LHqu3yhPMlFT0IosskBfdI9+pALPKsxjhkOU6UfFMpIjOiMtNjlcqnPTVhsaax13O4Ujyb 50q8EF2Fv/u8wuNzOvhg9rgzQsBBAKk= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 18:02:15 +0100 Message-Id: <23651b7a24a6fd90997a2faf97e0bbae08f946d7.1573578043.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 Subject: [libvirt] [PATCH 7/9] tests: delete tests for VIR_STR(N)DUP 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 X-MC-Unique: NGOOwoEaNFqu-q_eaI7j1w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza --- tests/virstringtest.c | 136 ------------------------------------------ 1 file changed, 136 deletions(-) diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 1e408f2757..992b25df92 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -236,136 +236,6 @@ static int testRemove(const void *args) } =20 =20 -static bool fail; - -static const char * -testStrdupLookup1(size_t i) -{ - switch (i) { - case 0: - return "hello"; - case 1: - return NULL; - default: - fail =3D true; - return "oops"; - } -} - -static size_t -testStrdupLookup2(size_t i) -{ - if (i) - fail =3D true; - return 5; -} - -static int -testStrdup(const void *data G_GNUC_UNUSED) -{ - char *array[] =3D { NULL, NULL }; - size_t i =3D 0; - size_t j =3D 0; - size_t k =3D 0; - int ret =3D -1; - int value; - - value =3D VIR_STRDUP(array[i++], testStrdupLookup1(j++)); - if (value !=3D 1) { - virFilePrintf(stderr, "unexpected strdup result %d, expected 1\n",= value); - goto cleanup; - } - /* coverity[dead_error_begin] */ - if (i !=3D 1) { - virFilePrintf(stderr, "unexpected side effects i=3D%zu, expected 1= \n", i); - goto cleanup; - } - /* coverity[dead_error_begin] */ - if (j !=3D 1) { - virFilePrintf(stderr, "unexpected side effects j=3D%zu, expected 1= \n", j); - goto cleanup; - } - if (STRNEQ_NULLABLE(array[0], "hello") || array[1]) { - virFilePrintf(stderr, "incorrect array contents '%s' '%s'\n", - NULLSTR(array[0]), NULLSTR(array[1])); - goto cleanup; - } - - value =3D VIR_STRNDUP(array[i++], testStrdupLookup1(j++), - testStrdupLookup2(k++)); - if (value !=3D 0) { - virFilePrintf(stderr, "unexpected strdup result %d, expected 0\n",= value); - goto cleanup; - } - /* coverity[dead_error_begin] */ - if (i !=3D 2) { - virFilePrintf(stderr, "unexpected side effects i=3D%zu, expected 2= \n", i); - goto cleanup; - } - /* coverity[dead_error_begin] */ - if (j !=3D 2) { - virFilePrintf(stderr, "unexpected side effects j=3D%zu, expected 2= \n", j); - goto cleanup; - } - /* coverity[dead_error_begin] */ - if (k !=3D 1) { - virFilePrintf(stderr, "unexpected side effects k=3D%zu, expected 1= \n", k); - goto cleanup; - } - if (STRNEQ_NULLABLE(array[0], "hello") || array[1]) { - virFilePrintf(stderr, "incorrect array contents '%s' '%s'\n", - NULLSTR(array[0]), NULLSTR(array[1])); - goto cleanup; - } - - if (fail) { - virFilePrintf(stderr, "side effects failed\n"); - goto cleanup; - } - - ret =3D 0; - cleanup: - for (i =3D 0; i < G_N_ELEMENTS(array); i++) - VIR_FREE(array[i]); - return ret; -} - -static int -testStrndupNegative(const void *opaque G_GNUC_UNUSED) -{ - int ret =3D -1; - char *dst; - const char *src =3D "Hello world"; - int value; - - if ((value =3D VIR_STRNDUP(dst, src, 5)) !=3D 1) { - fprintf(stderr, "unexpected virStrndup result %d, expected 1\n", v= alue); - goto cleanup; - } - - if (STRNEQ_NULLABLE(dst, "Hello")) { - fprintf(stderr, "unexpected content '%s'", dst); - goto cleanup; - } - - VIR_FREE(dst); - if ((value =3D VIR_STRNDUP(dst, src, -1)) !=3D 1) { - fprintf(stderr, "unexpected virStrndup result %d, expected 1\n", v= alue); - goto cleanup; - } - - if (STRNEQ_NULLABLE(dst, src)) { - fprintf(stderr, "unexpected content '%s'", dst); - goto cleanup; - } - - ret =3D 0; - cleanup: - VIR_FREE(dst); - return ret; -} - - static int testStringSortCompare(const void *opaque G_GNUC_UNUSED) { @@ -853,12 +723,6 @@ mymain(void) const char *tokens8[] =3D { "gluster", "rdma", NULL }; TEST_SPLIT("gluster+rdma", "+", 2, tokens8); =20 - if (virTestRun("strdup", testStrdup, NULL) < 0) - ret =3D -1; - - if (virTestRun("strdup", testStrndupNegative, NULL) < 0) - ret =3D -1; - if (virTestRun("virStringSortCompare", testStringSortCompare, NULL) < = 0) ret =3D -1; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:22:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1573578129; cv=none; d=zoho.com; s=zohoarc; b=MgkstefJ6F/2Y0G+Xxk7YdeYrVs+LvYQ26GK0BswLTPdXVrMH2fzscZU/aPgASfILtsAQ2S0AVQaLofnZu+SIfyoEiIKJRE0jfumDvCpAP8fv1LWCLMppQwmE7xl8/0KQ0ZHtLXNUPIfjh9/ouX9HL6Gv7ffeJm2vOararneoqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573578129; 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=eejWGkhU5hTfapPQBVy6e/UI1ICOKX3cVmZtJbSXeCQ=; b=g/PM3fJ4P9TroFq7PALRnGC/MwrFr1DPnT1sOOPliG7IM3CBqLOuHu1zExi/hv/KryaEu7RfI5FHeQfoS6UN0zZ74mhlxw6VA894szAUxFoU8rvtx5oF0/25XqQS1lsQljl54+zN+e7anuSyGae51hpDN06lSoYmZ1tWiGaQgXA= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1573578129531976.0974100466368; Tue, 12 Nov 2019 09:02:09 -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-264-rWWSj1aJMQKa19mYmLYvlQ-1; Tue, 12 Nov 2019 12:02:02 -0500 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 8E91C183B52E; Tue, 12 Nov 2019 17:01:54 +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 5F6781968C; Tue, 12 Nov 2019 17:01:54 +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 1057118033B0; Tue, 12 Nov 2019 17:01:54 +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 xACH1XUM012332 for ; Tue, 12 Nov 2019 12:01:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 922C560173; Tue, 12 Nov 2019 17:01:33 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A72F600D5 for ; Tue, 12 Nov 2019 17:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573578128; 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=eejWGkhU5hTfapPQBVy6e/UI1ICOKX3cVmZtJbSXeCQ=; b=EAUQJUAf8BvTAAlOcvxWxy7yVwR9SWPrAeS1dNMBO0CMagYTqHJaCgqFA9hlVkQwPRALYF /gmqH4cbP88Eg4mXZe1wfjxpmg4HOPSlqT3VS4qVJdy+5WsE99slgBtWkL7FdolOjkkt2/ CmyqnIoe2HOW8vzUGmySUyqN3kECQmk= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 18:02:16 +0100 Message-Id: <6923e8fc554d2421e7e22456154b4cb183ea1bfa.1573578043.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 Subject: [libvirt] [PATCH 8/9] util: remove VIR_STRDUP and VIR_STRNDUP 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 X-MC-Unique: rWWSj1aJMQKa19mYmLYvlQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 2 -- src/util/virstring.c | 49 ---------------------------- src/util/virstring.h | 69 ---------------------------------------- 3 files changed, 120 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5787338e92..00e5054689 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3073,7 +3073,6 @@ virSkipSpaces; virSkipSpacesAndBackslash; virSkipSpacesBackwards; virStrcpy; -virStrdup; virStringBufferIsPrintable; virStringFilterChars; virStringHasCaseSuffix; @@ -3108,7 +3107,6 @@ virStringStripSuffix; virStringToUpper; virStringTrimOptionalNewline; virStrncpy; -virStrndup; virStrToDouble; virStrToLong_i; virStrToLong_l; diff --git a/src/util/virstring.c b/src/util/virstring.c index cd4418d144..10e544f959 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -888,55 +888,6 @@ virStringIsEmpty(const char *str) return str[0] =3D=3D '\0'; } =20 -/** - * virStrdup: - * @dest: where to store duplicated string - * @src: the source string to duplicate - * - * Wrapper over strdup, which aborts on OOM error. - * - * Returns: 0 for NULL src, 1 on successful copy, aborts on OOM - */ -int -virStrdup(char **dest, - const char *src) -{ - *dest =3D NULL; - if (!src) - return 0; - *dest =3D g_strdup(src); - - return 1; -} - -/** - * virStrndup: - * @dest: where to store duplicated string - * @src: the source string to duplicate - * @n: how many bytes to copy - * - * Wrapper over strndup, which aborts on OOM error. - * - * In case @n is smaller than zero, the whole @src string is - * copied. - * - * Returns: 0 for NULL src, 1 on successful copy, aborts on OOM - */ -int -virStrndup(char **dest, - const char *src, - ssize_t n) -{ - *dest =3D NULL; - if (!src) - return 0; - if (n < 0) - n =3D strlen(src); - *dest =3D g_strndup(src, n); - - return 1; -} - =20 size_t virStringListLength(const char * const *strings) { diff --git a/src/util/virstring.h b/src/util/virstring.h index 081a5ff1aa..a2cd92cf83 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -134,75 +134,6 @@ int virStrdup(char **dest, const char *src) int virStrndup(char **dest, const char *src, ssize_t n) G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1); =20 -/** - * VIR_STRDUP: - * @dst: variable to hold result (char*, not char**) - * @src: string to duplicate - * - * DEPRECATED: use g_strdup instead - * - * Duplicate @src string and store it into @dst. - * - * This macro is safe to use on arguments with side effects. - * - * Returns 0 if @src was NULL, 1 if @src was copied, aborts on OOM - */ -#define VIR_STRDUP(dst, src) virStrdup(&(dst), src) - -/** - * VIR_STRDUP_QUIET: - * @dst: variable to hold result (char*, not char**) - * @src: string to duplicate - * - * DEPRECATED: use g_strdup instead - * - * Duplicate @src string and store it into @dst. - * - * This macro is safe to use on arguments with side effects. - * - * Returns 0 if @src was NULL, 1 if @src was copied, aborts on OOM - */ -#define VIR_STRDUP_QUIET(dst, src) VIR_STRDUP(dst, src) - -/** - * VIR_STRNDUP: - * @dst: variable to hold result (char*, not char**) - * @src: string to duplicate - * @n: the maximum number of bytes to copy - * - * DEPRECATED: use g_strndup instead - * - * Duplicate @src string and store it into @dst. If @src is longer than @n, - * only @n bytes are copied and terminating null byte '\0' is added. If @n - * is a negative number, then the whole @src string is copied. That is, - * VIR_STRDUP(dst, src) and VIR_STRNDUP(dst, src, -1) are equal. - * - * This macro is safe to use on arguments with side effects. - * - * Returns 0 if @src was NULL, 1 if @src was copied, aborts on OOM - */ -#define VIR_STRNDUP(dst, src, n) virStrndup(&(dst), src, n) - -/** - * VIR_STRNDUP_QUIET: - * @dst: variable to hold result (char*, not char**) - * @src: string to duplicate - * @n: the maximum number of bytes to copy - * - * DEPRECATED: use g_strndup instead - * - * Duplicate @src string and store it into @dst. If @src is longer than @n, - * only @n bytes are copied and terminating null byte '\0' is added. If @n - * is a negative number, then the whole @src string is copied. That is, - * VIR_STRDUP_QUIET(dst, src) and VIR_STRNDUP_QUIET(dst, src, -1) are - * equal. - * - * This macro is safe to use on arguments with side effects. - * - * Returns 0 if @src was NULL, 1 if @src was copied, aborts on OOM - */ -#define VIR_STRNDUP_QUIET(dst, src, n) virStrndup(&(dst), src, n) - size_t virStringListLength(const char * const *strings); =20 int virStringSortCompare(const void *a, const void *b); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:22:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1573578116; cv=none; d=zoho.com; s=zohoarc; b=orNM5FpM0xwRrR/+VRV1LgNdJaJvub+y6etRNEXVRHICXc5aezoEAymMm7dpu/TcdCxWn1BT/XCt9UfW9DceDUCZEC2CFnv8wur3dZCH9PDv+HCYJ2ACLwBOEegoVNHZ3XOXHz3RMByI/dAGH5YSDcqN14/wIJwhKI9T2xdzsDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573578116; 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=1tADRzuZlMMRFX7lI8TODWjc9XtI1YbVQBLj/4mLf3w=; b=O4Vj8B+KOT/v8AYXf+3xW4hHo88/VZcEY0/ycQ1an+NuPMYgJBdcikhac5NLlllcYmD2CQmHdddMijDf7oOK5giZoyAnq3Mar4dBhEu9IvRtVE1BpR2RJyJwgJ7HGQdqJ2qx4EE7H4ReTP96KEz2hiG6MXjTEAlpr9qnhPNXfN8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573578116301935.8056346394072; Tue, 12 Nov 2019 09:01:56 -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-262-qFeB4FgGPmiajgLC-s8DPA-1; Tue, 12 Nov 2019 12:01:51 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3073C8C4A6F; Tue, 12 Nov 2019 17:01:45 +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 EB9BFBEA73; Tue, 12 Nov 2019 17:01:44 +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 82F7A18034FB; Tue, 12 Nov 2019 17:01:44 +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 xACH1Yor012339 for ; Tue, 12 Nov 2019 12:01:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 65314600D5; Tue, 12 Nov 2019 17:01:34 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id E16276016E for ; Tue, 12 Nov 2019 17:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573578115; 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=1tADRzuZlMMRFX7lI8TODWjc9XtI1YbVQBLj/4mLf3w=; b=NKGe/Qi09s77MCwP8DeOIGZ8CyjXLwM3jvQU9G8QJ/rPqG3RzuqUZHXcoNxvhvV0FiuexM pn15vHhc6/9P+jwnUC/JvVaisONiuOpTZm63euSh/EvgVi6gY7y4d8qQpP+3VqChhhxXc3 NPULbG/rPDVW/CUzDmRLuaXHGJOX9Dw= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 18:02:17 +0100 Message-Id: <8659d0b4943a7b1c8f92c6ec5c1ccce76b02de30.1573578043.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 Subject: [libvirt] [PATCH 9/9] docs: hacking: document removal of VIR_STR(N)DUP 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.15 X-MC-Unique: qFeB4FgGPmiajgLC-s8DPA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza --- docs/hacking.html.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 06deab9e90..74aba5d46b 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -1040,9 +1040,6 @@ BAD: a single method. Keep the style consistent, converting existing code to GLib style in a separate, prior commit. =20 -
VIR_STRDUP, VIR_STRNDUP
-
Prefer the GLib APIs g_strdup and g_strndup.
-
virStrerror
The GLib g_strerror() function should be used inste= ad, which has a simpler calling convention as an added benefit.
@@ -1071,8 +1068,6 @@ BAD:

String allocation macros and functions:

= - = - @@ -1108,6 +1103,9 @@ BAD:
The GLib macros g_autoptr and G_DEFINE_AUTOPT= R_CLEANUP_FUNC should be used to manage autoclean of virObject classes. This matches usage with GObject classes.
+ +
VIR_STRDUP, VIR_STRNDUP
+
Prefer the GLib APIs g_strdup and g_strndup.
deprecated versionGLib versionNotes
VIR_STRDUPg_strdup
VIR_STRNDUPg_strndup
virAsprintfg_strdup_printf
virVasprintfg_strdup_vprint use g_vasprintf if you really need to know th= e returned length
@@ -1128,6 +1126,8 @@ BAD: + = +
deleted versionGLib versionNotes
ATTRIBUTE_RETURN_CHECKG_GNUC_W= ARN_UNUSED_RESULT
ATTRIBUTE_SENTINELG_GNUC_NULL_= TERMINATED
ATTRIBUTE_UNUSEDG_GNUC_UNUSED<= /code>
VIR_STRDUPg_strdup
VIR_STRNDUPg_strndup
=20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list