From nobody Mon Feb 9 16:34:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614696688; cv=none; d=zohomail.com; s=zohoarc; b=fMHWGI8ND7u2aForzS560k9/OsO2FtyOS382NNbLkd7amvIL8q0NNqJMmKtZQznJGFzKTYfIY/X4yf5tK4JU2jdyMJp6ZI6reHr+t9Thfh/f1cr25rerGCZ2DJE1DyPuq7epCjpZf0LnNqfBsOlOlw8k1pzptANXkXZIt7q+8ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696688; 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=S2eMo1TxG6PRDs4G1dGJYqrttNpMZHfdQTU4zghMh0Y=; b=I4NpK8Vo1zb1VYEULbI00iW9aXSFWtlTY9XvjIWRqy5KA85OChg8ErpNSBqflf67Mb/SqjW6EOwSi3biawElArAGR74gOluuSDDuSZr+FUt4OQ3mNxKsysTlrUR/kfFUBzWy3wnSB9uMyhyUnjj5x59H3Lj5F1CBgM2o9CJwmH0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614696688572972.2981253111203; Tue, 2 Mar 2021 06:51:28 -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-351-OOw8N40lMy6n4g-eHGk-6Q-1; Tue, 02 Mar 2021 09:50:21 -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 6A27D801983; Tue, 2 Mar 2021 14:50:15 +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 44B095D9E2; Tue, 2 Mar 2021 14:50:15 +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 0928B1800237; Tue, 2 Mar 2021 14:50:15 +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 122EnwrH014589 for ; Tue, 2 Mar 2021 09:49:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id C66EC5D768; Tue, 2 Mar 2021 14:49:58 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 354FB5D722 for ; Tue, 2 Mar 2021 14:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696686; 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=S2eMo1TxG6PRDs4G1dGJYqrttNpMZHfdQTU4zghMh0Y=; b=YFyreTwc2IiDbg4a+ejzg/Z9uqvYykFkfcCIPcSjq9gir5QoY6Vp+fgGD5zSs040TubBbX e/OI3bg587jiTDRCe3N1eEYWbyzniKdiAaeSYEEZT/ZKbXqscZNf0zXEE0il+EvrHx0Ndt vj+6hXViPVwXfuqPwaxlp9Qg7vt8R/Q= X-MC-Unique: OOw8N40lMy6n4g-eHGk-6Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/16] util: virstring: Remove virStrncpy Date: Tue, 2 Mar 2021 15:49:33 +0100 Message-Id: <8dad823eeae2499263c6cc8e225716a7f23ab41d.1614696480.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The function is now unused and motivated users to write crazy parsers which were hard to understand, had pointless error paths just to avoid few memory allocations. Remove the function as we're fine with g_strndup and virStrcpy. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- docs/coding-style.rst | 13 ------------ src/libvirt_private.syms | 1 - src/util/virstring.c | 44 ---------------------------------------- src/util/virstring.h | 2 -- 4 files changed, 60 deletions(-) diff --git a/docs/coding-style.rst b/docs/coding-style.rst index 55dfa196a2..c43d20c7b2 100644 --- a/docs/coding-style.rst +++ b/docs/coding-style.rst @@ -714,19 +714,6 @@ does **not** guarantee a NULL-terminated buffer, which= makes it extremely dangerous to use. Instead, use one of the replacement functions provided by libvirt: -:: - - virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) - -The first two arguments have the same meaning as for strncpy, -namely the destination and source of the copy operation. Unlike -strncpy, the function will always copy exactly the number of bytes -requested and make sure the destination is NULL-terminated, as the -source is required to be; sanity checks are performed to ensure -the size of the destination, as specified by the last argument, is -sufficient for the operation to succeed. On success, 0 is -returned; on failure, a value <0 is returned instead. - :: virStrcpy(char *dest, const char *src, size_t destbytes) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2a3bbdc577..eb121032d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3264,7 +3264,6 @@ virStringStripIPv6Brackets; virStringStripSuffix; virStringToUpper; virStringTrimOptionalNewline; -virStrncpy; virStrToDouble; virStrToLong_i; virStrToLong_l; diff --git a/src/util/virstring.c b/src/util/virstring.c index a35cd8ba76..1d6141b5c1 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -452,50 +452,6 @@ virDoubleToStr(char **strp, double number) } -/** - * virStrncpy: - * - * @dest: destination buffer - * @src: source buffer - * @n: number of bytes to copy - * @destbytes: number of bytes the destination can accommodate - * - * Copies the first @n bytes of @src to @dest. - * - * @src must be NULL-terminated; if successful, @dest is guaranteed to - * be NULL-terminated as well. - * - * @n must be a reasonable value, that is, it must not exceed either - * the length of @src or the size of @dest. For the latter constraint, - * the fact that @dest needs to accommodate a NULL byte in addition to - * the bytes copied from @src must be taken into account. - * - * If you want to copy *all* of @src to @dest, use virStrcpy() or - * virStrcpyStatic() instead. - * - * Returns: 0 on success, <0 on failure. - */ -int -virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) -{ - size_t src_len =3D strlen(src); - - /* As a special case, -1 means "copy the entire string". - * - * This is to avoid calling strlen() twice, once in the virStrcpy() - * wrapper and once here for bound checking purposes. */ - if (n =3D=3D -1) - n =3D src_len; - - if (n > src_len || n > (destbytes - 1)) - return -1; - - memcpy(dest, src, n); - dest[n] =3D '\0'; - - return 0; -} - /** * virStrcpy: * diff --git a/src/util/virstring.h b/src/util/virstring.h index da1fe86ffc..e688495574 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -97,8 +97,6 @@ void virSkipSpacesBackwards(const char *str, char **endp) bool virStringIsEmpty(const char *str); -int virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) - G_GNUC_WARN_UNUSED_RESULT; int virStrcpy(char *dest, const char *src, size_t destbytes); #define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) --=20 2.29.2