From nobody Fri May 3 12:07:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576070564; cv=none; d=zohomail.com; s=zohoarc; b=nTiReLIObLXaS83Ok7X4TvcTjDCEFOYNYqefLg0ZIszprpan7uyd0OpD1eU7XyxFh22SXpqaWUw2mVprSoy/UWA/pKKdnT6U4cMo0QNFbRcAWJqLyFdZ0rl5NP4R5fH47vuHF2PL9bp+MeAfk+CwkL6ToMbA1y85EKjR8GFxIZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576070564; 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=yViDNr7EXDJwqq9uOujmiX9iPzCRcwXRGWdZFtRik1E=; b=Tmy5G0Qlfo6zvXOkvzaRz1BP5vCXIDc1KK57Q5nQwj7dCuLXT2NmWmhqgsHR9yROPBmfWklS0kLib7psEprtEYWEs+r2j6Vya/65kSi5GUb3TnyoKHg7UpLWR+oba89H2bti1mMS+zevMLFR2j8/sjWdb/Eu+VEv/z6BeLwJNWs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1576070564636312.6143876652046; Wed, 11 Dec 2019 05:22:44 -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-354-CGNVIchdPvOsvZHsQ4uhrA-1; Wed, 11 Dec 2019 08:22:41 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82585DB2C; Wed, 11 Dec 2019 13:22:30 +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 529FF1001B07; Wed, 11 Dec 2019 13:22: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 08FD0182B00F; Wed, 11 Dec 2019 13:22:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBBDMRX2019642 for ; Wed, 11 Dec 2019 08:22:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id A050863BCC; Wed, 11 Dec 2019 13:22:27 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27EBB63BC6 for ; Wed, 11 Dec 2019 13:22:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576070563; 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=yViDNr7EXDJwqq9uOujmiX9iPzCRcwXRGWdZFtRik1E=; b=cah2LLg2YbwuRxXTtrNleAkue0aya8EEpQHhrlivkNUmvgB2yzX1GvZPXjaxVvpuc2CpT9 3X4kZTXhhIj0Dv2ggpKAnnofjeyVd8pf8iMQ4DaTmLulkz8xcOuFccxO8iy9AmPk5Jt+/9 iXb8mNk7ZqT009B06ZgkdDnvhU9QQfI= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 11 Dec 2019 14:23:17 +0100 Message-Id: <48bb3b761c363f4bfe55795d96da109595827844.1576070578.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 1/8] Remove VIR_STRDUP usage that sneaked in in the meantime X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: CGNVIchdPvOsvZHsQ4uhrA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) My hesitation to remove VIR_STRDUP without VIR_STRNDUP resulted in these being able to sneak in. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- src/conf/backup_conf.c | 4 +--- src/qemu/qemu_monitor_json.c | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index 6be2e0498e..aa11967d2a 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -483,9 +483,7 @@ virDomainBackupAlignDisks(virDomainBackupDefPtr def, continue; =20 backupdisk =3D &def->disks[ndisks++]; - - if (VIR_STRDUP(backupdisk->name, domdisk->dst) < 0) - return -1; + backupdisk->name =3D g_strdup(domdisk->dst); =20 if (backup_all && !virStorageSourceIsEmpty(domdisk->src) && diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 00e1d3ce15..8a8347924a 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5564,8 +5564,7 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, goto cleanup; } =20 - if (VIR_STRDUP(info->defaultCPU, tmp) < 0) - goto cleanup; + info->defaultCPU =3D g_strdup(tmp); } } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 12:07:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1576070580; cv=none; d=zohomail.com; s=zohoarc; b=acdg9jZazpaUr5U8qt1n2pxM9TTIEg9xGyvEC92bpqWQcoAPn55Qwn3XU0Gaz97yA4hYS6j3c+YsZ8go9L7GmEySES2UQI3aCUZiomoPWovHue6JQAwWGcodDX47NfWsPIQFYy1DkXZADCJZrDlj3kVVVXNz/g9N51vAGkXvGo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576070580; 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=FkWA15Dm5QDYwRUX/1ZZG9ks8BmV1erLmOQathxacUM=; b=lFT/A7s40Go8BJDxAvhr/G9G1WxpRCB4ogbiusnoMU63Fw9ANanp+2hIq1jYJ+FN31oz0+ET33hZoJ/DYs6VGlinCnUsEzD0IKX5MXMKJREx7fEZX0D8i0YwPt2SrNjA3k9yp4QSlx9GFxnZ254QDT3sD/U26CwsXyn7JC3Pgu4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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 [207.211.31.81]) by mx.zohomail.com with SMTPS id 1576070580626245.4019798149559; Wed, 11 Dec 2019 05:23:00 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-375-goT8m7jsO12wrEaFbefdCw-1; Wed, 11 Dec 2019 08:22:57 -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 5E166800D4E; Wed, 11 Dec 2019 13:22:52 +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 37E9760BB5; Wed, 11 Dec 2019 13:22:52 +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 E39A7182B013; Wed, 11 Dec 2019 13:22:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBBDMUYx019716 for ; Wed, 11 Dec 2019 08:22:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 532F463BBA; Wed, 11 Dec 2019 13:22:30 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id D040C67583 for ; Wed, 11 Dec 2019 13:22:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576070579; 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=FkWA15Dm5QDYwRUX/1ZZG9ks8BmV1erLmOQathxacUM=; b=PyjYcbWStDWLGda54hN9IbeAJXu0hC4EkgJ3KJNEDNcd4kD8co97D8rC8Agk05gEPBwxAv 3Ujbf2/ZQ5obc/+ZIQLc9fkxvTmVfS8vqqp8D0/tTWbPH1xU9p6HhbpRzNhSW2rlk7v7Q3 4tXoZfDB1h3rbPzYHYYo6MBw3DrvP84= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 11 Dec 2019 14:23:18 +0100 Message-Id: <203a24db2480e67952beb845e42175c8df35112d.1576070578.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 2/8] vsh: remove vshErrorOOM 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: goT8m7jsO12wrEaFbefdCw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) We abort on allocation errors now so there is no need to have a function for it. Replace the only use by return -1, chosen by fair dice roll. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- tools/vsh.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 6c78a7a373..dd2c039b47 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -64,17 +64,6 @@ const vshCmdGrp *cmdGroups; const vshCmdDef *cmdSet; =20 =20 -/* simple handler for oom conditions */ -static void -vshErrorOOM(void) -{ - fflush(stdout); - fputs(_("error: Out of memory\n"), stderr); - fflush(stderr); - exit(EXIT_FAILURE); -} - - double vshPrettyCapacity(unsigned long long val, const char **unit) { @@ -361,7 +350,7 @@ vshCmddefCheckInternals(vshControl *ctl, } if ((p =3D strchr(name, '=3D')) && VIR_STRNDUP(name, name, p - name) < 0) - vshErrorOOM(); + return -1; 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 Fri May 3 12:07:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576070604; cv=none; d=zohomail.com; s=zohoarc; b=GRT+8GOSi6UDDqXmU6B/tAY8FuTHV+74UvFCE++C/RTfZyhmnfEQxK9iDz4wbA87jGJP0ia6udAGLDC0Ajt96KT6rgxgrydiAAG5FRsR/ynXkYxddvcEABZ8tEB4qAHoKx8ASVMTdOA9QNqmZgS5aCvdxwa/QIQ7Q34UHylvnlU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576070604; 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=ropkeQiqxkSEacUb28fHpJDd1Il6T3xVUsdaZCHiSFI=; b=N/lk4rnH02/WV4Ztp2fuALXP/wNhozSKEvqEC6MsxU2eiCOj7ZG30tp1zifmxcHHVLNge6VwBBUi7xPBDtPqpCX8LNeSBZW6wEBnoD0b4HDGv4YpNmd9yRdXacjlg3UbVLd/l351Pm79oSneyaet6Gjh4PsTZoH0/AxlTCtgg80= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1576070604413154.95435048929915; Wed, 11 Dec 2019 05:23:24 -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-64-c2aIoQDgOJWc6jRa4dM5Eg-1; Wed, 11 Dec 2019 08:23:20 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31235DB20; Wed, 11 Dec 2019 13:23:14 +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 08E601001938; Wed, 11 Dec 2019 13:23:14 +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 B3CE683714; Wed, 11 Dec 2019 13:23:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBBDMXPX019795 for ; Wed, 11 Dec 2019 08:22:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 414B963BC6; Wed, 11 Dec 2019 13:22:33 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE6E963BBA for ; Wed, 11 Dec 2019 13:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576070603; 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=ropkeQiqxkSEacUb28fHpJDd1Il6T3xVUsdaZCHiSFI=; b=S5hjNf3s728qNy6vwHzQ/C/R7vhacSfJ5PmvZcbJGuus28vyIXdEcVq3zseA5J0QGT+ocG bQRFFmKIjUUFJMk5qGNto/t0uA82Q0E4Cwu+ms/ImUPtzFqdKQWLmRjOfEe4l2v31dvrx1 H4PJQfeXN/1BHSCMm47kBRcOcbsSQb8= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 11 Dec 2019 14:23:19 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 3/8] 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.84 on 10.5.11.22 X-MC-Unique: c2aIoQDgOJWc6jRa4dM5Eg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Michal Privoznik --- 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 8c07df80b6..912dd8834a 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -815,9 +815,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++; @@ -843,9 +842,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) { @@ -860,10 +859,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 dd2c039b47..5ccda5ab44 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -348,9 +348,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) - return -1; + 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 Fri May 3 12:07:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576070626; cv=none; d=zohomail.com; s=zohoarc; b=b6dLCK6xV5Lv7MqYeUPfLTkNW6rFNVr17mUY5Mveod6jUymi8Q0HPU5b/JUNQJLblgjED0j8myemcmRoQBStICIjOCYfxbuZwu7wYOF4YgfnW4iMQLnxzzzMpzQ8eA9RyM+e4DxjXUgBA5g5Av5xVKWTnXh3JQe+CkqYAAt6zQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576070626; 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=dqzDDH7XZgiPcAYtkkxYcZFd2L0uPFB6mG4tGom9yHI=; b=nfdkVrbtpdcCXDbxF3tDBIp5uXtiZ73H3mFT0+yT7uFdBJyLQVHsitIzXbxEuNUjnc7UY1wOXYfFg+UwSy1Zl0NV2CisonXviqa9yqw+pBFaQLagRHfYffyO7ABaWE1FNzpQbsGqAi70Z1DiDva8Y730P+n2RfBdcKtuceycb7M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1576070626155629.3466611827126; Wed, 11 Dec 2019 05:23:46 -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-236-8jZbfFrRNg-8OqCAw8fx7Q-1; Wed, 11 Dec 2019 08:23:41 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA3921005502; Wed, 11 Dec 2019 13:23:35 +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 B34601001902; Wed, 11 Dec 2019 13:23:35 +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 6D6A1182B014; Wed, 11 Dec 2019 13:23:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBBDMZSf019862 for ; Wed, 11 Dec 2019 08:22:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id A401F63BBA; Wed, 11 Dec 2019 13:22:35 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A83163BCD for ; Wed, 11 Dec 2019 13:22:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576070624; 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=dqzDDH7XZgiPcAYtkkxYcZFd2L0uPFB6mG4tGom9yHI=; b=i7gcsGIui0aezzELREe4haJzqOo30A8CWMlnu+kNLf3RNjb0j0k3Tu443iziSl3VVXXYwk PVyrhgCl3hosWxrZd50b52KUivHUGP8WaEdOSumK24wqGgiFjDljJzbkaiTXrXz4dIH4Bn iagP+tp5KhnmIGQNbYE4pxp6uKu3CKc= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 11 Dec 2019 14:23:20 +0100 Message-Id: <46310b7daac7126ef6d73523e14daf76d8f24d82.1576070578.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 4/8] Remove all the uses that use subtraction in their length argument X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 8jZbfFrRNg-8OqCAw8fx7Q-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza Reviewed-by: Michal Privoznik --- 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 | 1 - src/util/virconf.c | 24 +++++++----------------- src/util/viriscsi.c | 3 +-- src/util/virkeyfile.c | 6 ++---- src/util/virstoragefile.c | 3 +-- src/util/virsysinfo.c | 3 +-- src/vmware/vmware_conf.c | 6 +----- 14 files changed, 25 insertions(+), 57 deletions(-) diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_comman= d.c index 5eec05c7d4..e74c4c2d0c 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -282,8 +282,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) { @@ -578,8 +577,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 912dd8834a..89ced6ae2b 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -848,9 +848,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) { @@ -992,8 +991,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 1b462d0487..a196912194 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 b40a96b4ce..fbf49ee957 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2137,8 +2137,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 4d77fd6f6a..47665f4ea6 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9251,8 +9251,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 8a8347924a..b2f695a70c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -643,15 +643,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 40eafd7552..4f6b89cf2e 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -780,9 +780,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 e677b67b93..dd37b0b8dc 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -3138,7 +3138,6 @@ virCommandRunRegex(virCommandPtr cmd, /* NB match #0 is the full pattern, so we offset j by 1 */ for (j =3D 1; j <=3D nvars[i]; j++) groups[ngroup++] =3D g_match_info_fetch(info, j); - } /* We've matched on the last regex, so callback time */ if (i =3D=3D nregex) { diff --git a/src/util/virconf.c b/src/util/virconf.c index 3b45436499..dce84cabb7 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) && (IS_BLANK(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/viriscsi.c b/src/util/viriscsi.c index da27894b0b..ac48527dde 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -160,8 +160,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/virkeyfile.c b/src/util/virkeyfile.c index a98d60cdb1..ece31667ce 100644 --- a/src/util/virkeyfile.c +++ b/src/util/virkeyfile.c @@ -117,8 +117,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 @@ -161,8 +160,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 5e371694d1..8918f905a2 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2945,8 +2945,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/virsysinfo.c b/src/util/virsysinfo.c index ebb329bb6f..8132ab7a07 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 9f7d874c12..290e0e898d 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 Fri May 3 12:07:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576070646; cv=none; d=zohomail.com; s=zohoarc; b=nMSRnzbE+fpZT+otFkoDD6CQ46o9BE5jxD/Q6Flteu6x5hYdSZM0bc+dAcSLDMusxI9kNA4WBfksd+zewesd75SeDLIFe7kPMcP1dVtE6xhTlo38pTh5ifd3ceM/IEcy/gKwwGraBgNSWd6xrQuYsLLUTohRPE/UiHZKgc+C/nE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576070646; 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=wK8WbYqK4HW/OrS6UKA3e7Ew5CgGWQon2nO68AdiQLY=; b=GhXYiYoY8kFF4g3H1vkVIPIguT6s53tdBuj6QhTnPOqf8aFmEpDLvl0syKzE/3BIcq8ouVW8QT4RjkFl4/SGhg4FO+slZgi+86ZqxmSL1n6RxRKQTDge1hbcCKUJMRzlwuHgrB1Zjx37ab1W0OOKP5HNma6AsZep0zqDdTFz2gs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1576070646402289.5766259428585; Wed, 11 Dec 2019 05:24:06 -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-220--ZNQq9v2O2eYicjAu2rKQQ-1; Wed, 11 Dec 2019 08:24:03 -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 BB36C1010FFC; Wed, 11 Dec 2019 13:23:57 +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 94D315DA7B; Wed, 11 Dec 2019 13:23:57 +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 40A0C83716; Wed, 11 Dec 2019 13:23:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBBDMcPN019937 for ; Wed, 11 Dec 2019 08:22:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6D60263BC6; Wed, 11 Dec 2019 13:22:38 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7DA063BBA for ; Wed, 11 Dec 2019 13:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576070645; 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=wK8WbYqK4HW/OrS6UKA3e7Ew5CgGWQon2nO68AdiQLY=; b=a+M5ziKo22Akx4WG5Tqiyl+kt/qNsbIPkM1JOY/s7oARTVSDCQ/302GXW7PZ3frpkhg+js i6E9KCLDuGXkCFUClXPl445isjuaZUiCLeEMt2JFazSBuaGxn79TzQWLn8aAoZKD8Ureg4 nWh2L9J7I1jyug8hWVyFuNsNqgjtVwU= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 11 Dec 2019 14:23:21 +0100 Message-Id: <6ece16bb772847927426c3a9f55bc136d68bd095.1576070578.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 5/8] 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.14 X-MC-Unique: -ZNQq9v2O2eYicjAu2rKQQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Replace all the uses passing a single parameter as the length. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- 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/util/virjson.c | 11 +++-------- src/util/virkeyfile.c | 3 +-- src/util/virsocketaddr.c | 5 +---- src/util/virstoragefile.c | 3 +-- src/util/virstring.c | 3 +-- 13 files changed, 21 insertions(+), 47 deletions(-) diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 5bcf52a84c..d071c398bc 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -400,8 +400,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 b1a2c50f27..4110169135 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 7df5cf2cc3..26b1045f8a 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -953,12 +953,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 89ced6ae2b..415549a42c 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -1153,8 +1153,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 cdff71f11b..8112214b5f 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1104,13 +1104,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 a196912194..5d5d521c18 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 b2f695a70c..b4d103a37b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -271,8 +271,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/util/virjson.c b/src/util/virjson.c index c57dc11f78..988a09e956 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -462,10 +462,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; } @@ -1632,8 +1629,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 @@ -1690,8 +1686,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 ece31667ce..84b1b0e55a 100644 --- a/src/util/virkeyfile.c +++ b/src/util/virkeyfile.c @@ -173,8 +173,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 8918f905a2..14e1efc9e8 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -420,8 +420,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 bd7c640042..7cf32fda3e 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -89,8 +89,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 Fri May 3 12:07:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576070576; cv=none; d=zohomail.com; s=zohoarc; b=L7hA95pR6D5zRgyOv2UUF2C6I8+VMh1X72Xk3ZpaAQdTg0AKktY2y/LV0y2hiAgZbv+NRgwZg3kqTJx/PafIO8UpbFvjUhey10E4YTMzhJ7hxNienAdEnRGtVpNS9uAmmMcw8chATBo+qjScz++0NoP0nCprgCC83XuNOWJjPTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576070576; 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=wep4sIwt1t6N/OvYUriG4QaAab0MlyJw51CR83xk4T0=; b=AK7xkrrzqKNGDAaiR63sFWTIL8nUTZJhotMJzvEHXVXYWVCoceoTX8KCy44K5yz1julH7dF+jy5B99D3t6NOsGQEnd2lzgs6qtioSxg7A83fM/jEfGJIzKcRD3ahVxIxw+IKiRk+ekLbQuaF6kQukyZKrSKNZ729Rtbr61A7XWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1576070576517629.8008080082441; Wed, 11 Dec 2019 05:22: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-259-zNyXLG-YO6OPCcwQjj5V7Q-1; Wed, 11 Dec 2019 08:22:53 -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 634EF1005502; Wed, 11 Dec 2019 13:22:47 +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 321025C1B5; Wed, 11 Dec 2019 13:22:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CD2C583715; Wed, 11 Dec 2019 13:22:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBBDMfSM020012 for ; Wed, 11 Dec 2019 08:22:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 06DEC63BBA; Wed, 11 Dec 2019 13:22:41 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8329F63BC6 for ; Wed, 11 Dec 2019 13:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576070575; 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=wep4sIwt1t6N/OvYUriG4QaAab0MlyJw51CR83xk4T0=; b=AAU01SocpnxF+L1REoEZpckOd8eJF6c0xdBVcpYUtjg9k5Vi3m1wrk9ZB85ofwuiwtO0px 0wVYcrGz9R2y7qChhZfebQCSfSewRblrEVqopUzQT1SInCKt6lprQsqZ87FD6iMWe2Pm8n e38C6u5d4HzYFRozSSoZwTV4P7RARaQ= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 11 Dec 2019 14:23:22 +0100 Message-Id: <92272f4ada6fe68a1f6daafd01dbc369e10623a8.1576070578.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 6/8] 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.16 X-MC-Unique: zNyXLG-YO6OPCcwQjj5V7Q-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza Reviewed-by: Michal Privoznik --- tests/virstringtest.c | 136 ------------------------------------------ 1 file changed, 136 deletions(-) diff --git a/tests/virstringtest.c b/tests/virstringtest.c index fc5f9bf937..1f195ab4b9 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -233,136 +233,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) { @@ -847,12 +717,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 Fri May 3 12:07:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576070578; cv=none; d=zohomail.com; s=zohoarc; b=E0vmtq6Ek1vLbhTp3gXBMQpjxbi121/4FRKQ9TJ+5AMmdH361H27l13Xda6JNiLcO0EhFhATgiK2WP3UoXzR7ydQ7II1sHD04rFlGAluJechzlN0hfouVgPmgRfH7gEKJuPf0doJZctnoyUJRDdzu6c+TLgklhs0//Pko36/oE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576070578; 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=8Jj4yh1LErIVXF0AVRo7AOfI3SrhmTzrls3Ho0l63HA=; b=KaLFRaPwsyd7tkdBLCidoEwadMlsLsdZqOtoN2emEefdngVmgOpbzmoh7zS7zqv310NmYRBkORiRd4lo9ifp4BFc4zS8RV98ORbFWNdvkUOISgzGLFW/n/XyT/rKnnSJ3EiwaL597Lm9EzzRnju/vKo/hLad6rXBx0sqzmvkj3o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1576070578932518.5916336393424; Wed, 11 Dec 2019 05:22: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-438-HJJ6A1vQNciPnd82Z-MN0g-1; Wed, 11 Dec 2019 08:22:56 -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 9D792183B72B; Wed, 11 Dec 2019 13:22:50 +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 790685C1B5; Wed, 11 Dec 2019 13:22: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 37563182B011; Wed, 11 Dec 2019 13:22:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBBDMfW9020040 for ; Wed, 11 Dec 2019 08:22:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id CCED063BC6; Wed, 11 Dec 2019 13:22:41 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54EFE63BBA for ; Wed, 11 Dec 2019 13:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576070577; 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=8Jj4yh1LErIVXF0AVRo7AOfI3SrhmTzrls3Ho0l63HA=; b=V4YE/Tj1iukK5ZqwHrA65RUM7FyqQy29Hor+MUhH8ittUebik9MlxZFtwpgdXpcS0MZv/9 KZ5a5AvsVfqkyI0xc6gDS+5J5DBMNkijbliuV1FLeibvnkxW8pIWJxbDjyKTM8QYFucPeT +F6Yb95xVnrof37SCnw20h35FSZSfFY= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 11 Dec 2019 14:23:23 +0100 Message-Id: <02a63058b51ffcfe8f8b2d0c6f1ca9a838695bff.1576070578.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 7/8] 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.16 X-MC-Unique: HJJ6A1vQNciPnd82Z-MN0g-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza Reviewed-by: Michal Privoznik --- 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 4a342239e5..38e2ab915b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3114,7 +3114,6 @@ virSkipSpaces; virSkipSpacesAndBackslash; virSkipSpacesBackwards; virStrcpy; -virStrdup; virStringBufferIsPrintable; virStringFilterChars; virStringHasCaseSuffix; @@ -3149,7 +3148,6 @@ virStringStripSuffix; virStringToUpper; virStringTrimOptionalNewline; virStrncpy; -virStrndup; virStrToDouble; virStrToLong_i; virStrToLong_l; diff --git a/src/util/virstring.c b/src/util/virstring.c index 7cf32fda3e..fe5c026d2c 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -886,55 +886,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 Fri May 3 12:07:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1576070601; cv=none; d=zohomail.com; s=zohoarc; b=LTArDkb7guy/pwXgFso8aQPCn0e5x1SGqjWcUH15Go9CUHkaQqHnDsxBYhDmXZSkn2mhKmGOHRcmX1hrdcKLaLFijQinaLkeECuxZ7sR/8vElGvZ3B70sKEUYo5Z55h+gG35gA2q4UdxOR9AN87Hns3al7A0JGqOv9syLDCoDKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576070601; 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=Wr1tijwISoSCvTrRztbYz8Ix0yUdTiqHnd7hNY2t8mY=; b=jIyWFmVObCigVGJnaxnSL35TXPc65V99s8w39FCkxGY1zH1suQslvUKG5btkuANUHO8Cffnaqha+gWcgCwVN14bve84EABv+HO6O9IRQvHgzxj8AS6BihI7npeUIY+BjISKG8pm53N5yNVowz/ZHmk7iX0xk6hSuvJbGeA4mXnk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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 [207.211.31.81]) by mx.zohomail.com with SMTPS id 1576070601066698.0112348588538; Wed, 11 Dec 2019 05:23:21 -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-185-ZmLGKhvvOlmz_XOunqfp7Q-1; Wed, 11 Dec 2019 08:23:18 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A605100551A; Wed, 11 Dec 2019 13:23:12 +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 76BC41001B07; Wed, 11 Dec 2019 13:23:12 +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 2A056182B013; Wed, 11 Dec 2019 13:23:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBBDMjPr020136 for ; Wed, 11 Dec 2019 08:22:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2FB7863BC6; Wed, 11 Dec 2019 13:22:45 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.43.2.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC1E963BBA for ; Wed, 11 Dec 2019 13:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576070600; 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=Wr1tijwISoSCvTrRztbYz8Ix0yUdTiqHnd7hNY2t8mY=; b=eJQFc2AU4O3gt5GaWmYsSgMNN5A5oTVLIoolt5pJ17GKqPsYVsTT7Zoyy+fZNCgs8HCtOX v1WdhqKAHllA2vcY/qO1u258/spwz+YZASiRbshEvkb8rdZw6wTOGrHyf123T8WLJ1C2yP uudvpu26wt4v+/CCCrkB5lDvJwjdSzU= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 11 Dec 2019 14:23:24 +0100 Message-Id: <772b49d13a66ac8e2e2e86328f1950957e9a8a76.1576070578.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 8/8] 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.84 on 10.5.11.22 X-MC-Unique: ZmLGKhvvOlmz_XOunqfp7Q-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza Reviewed-by: Michal Privoznik --- 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