From nobody Mon Feb 9 19:30:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1681906449; cv=none; d=zohomail.com; s=zohoarc; b=n/VlrYXE7+kRNM1OPvrRhtfn/Y6psDfNAoTzuccEWzQKu0WXSP9SMopBc9tqOP3pUOkjljtga1j3QPL3c8t0e+CZzGQ6s6yr0NhBbzCA78YCJuZJPzQy8R7juqoVuFK+hf8K6KTbtEi5FLK8eeqX8aLUu1SjdLT5D2Xt5HwEz2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681906449; 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=2ydJfqfaBm/3WgPRF8v//tk5Ceze6MAnakX34ztshf8=; b=SjV+GyMgmzsE+7WQsHL4NSOyLHSq1GoWBtzuk0GSGpuVAgxgXE6xiqbUde3ZQnUGXGknAilxSDy8wgc8ZTKdUQfojJw8A6EhHNOKrQGwFCVRzj9oiCMmKZ+TiQkdVzRTrfRboA0tWLGQxzcxdveFlcW9NUGrjcCsDNOeMLoUNOQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 168190644978582.17509554785647; Wed, 19 Apr 2023 05:14:09 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-658-RZhmtcR5PxKHvzJIyOOkdw-1; Wed, 19 Apr 2023 08:14:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D0E48996F3; Wed, 19 Apr 2023 12:14:03 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DB1E2026D25; Wed, 19 Apr 2023 12:13:59 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B4D0819465B1; Wed, 19 Apr 2023 12:13:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9D18119465A0 for ; Wed, 19 Apr 2023 12:04:56 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9258D492B04; Wed, 19 Apr 2023 12:04:56 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id E048B492B06 for ; Wed, 19 Apr 2023 12:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681906448; 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=2ydJfqfaBm/3WgPRF8v//tk5Ceze6MAnakX34ztshf8=; b=W0gWIckgN1tjWRwQgJLQY3VjfYMsRbKb1jJRR5b6jvfVrISyVPu+Idedz0SnOKWachxEKs eSUaMjyR8WrxfmUIKi4FMmJ/WuD8eFLl4XVDPAnNxLJKKWhheiOJkLDik5o9r8HyDoDUs+ Y/6W26dua6LS13X8BwHXxkqVupOskGg= X-MC-Unique: RZhmtcR5PxKHvzJIyOOkdw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v3 14/25] util: virtypedparam: Store errors inside virTypedParamList Date: Wed, 19 Apr 2023 14:04:31 +0200 Message-Id: <0ea41656416185c6e425cdad981a9a768cc6bc63.1681905482.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681906450962100001 Content-Type: text/plain; charset="utf-8" The only non-abort()-ing error which can happen is if the field name is too long. Store the overly long name in the virTypedParamList container so that in upcoming patches the helpers adding to the list can be refactored to not have a return value. Signed-off-by: Peter Krempa --- src/util/virtypedparam.c | 62 ++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index 68698fe583..046164d36c 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -709,6 +709,8 @@ struct _virTypedParamList { virTypedParameterPtr par; size_t npar; size_t par_alloc; + + char *err_name; /* overly long field name for error message */ }; @@ -740,6 +742,9 @@ virTypedParamListConcat(virTypedParamList *to, memcpy(to->par + to->npar, from->par, sizeof(*(to->par)) * from->npar); to->npar +=3D from->npar; from->npar =3D 0; + + if (!to->err_name) + to->err_name =3D g_steal_pointer(&from->err_name); } @@ -750,6 +755,7 @@ virTypedParamListFree(virTypedParamList *list) return; virTypedParamsFree(list->par, list->npar); + g_free(list->err_name); g_free(list); } @@ -770,6 +776,12 @@ virTypedParamListFetch(virTypedParamList *list, virTypedParameterPtr *par, size_t *npar) { + if (list->err_name) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%1$s' too lo= ng"), + list->err_name); + return -1; + } + if (par) *par =3D list->par; @@ -815,17 +827,18 @@ virTypedParamListFromParams(virTypedParameterPtr *par= ams, } -static int G_GNUC_PRINTF(2, 0) -virTypedParamSetNameVPrintf(virTypedParameterPtr par, +static void G_GNUC_PRINTF(3, 0) +virTypedParamSetNameVPrintf(virTypedParamList *list, + virTypedParameterPtr par, const char *fmt, va_list ap) { - if (g_vsnprintf(par->field, VIR_TYPED_PARAM_FIELD_LENGTH, fmt, ap) > V= IR_TYPED_PARAM_FIELD_LENGTH) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Field name too lon= g")); - return -1; - } + g_autofree char *name =3D g_strdup_vprintf(fmt, ap); - return 0; + if (virStrcpyStatic(par->field, name) < 0) { + if (!list->err_name) + list->err_name =3D g_steal_pointer(&name); + } } @@ -848,15 +861,14 @@ virTypedParamListAddInt(virTypedParamList *list, { virTypedParameterPtr par =3D virTypedParamListExtend(list); va_list ap; - int ret; virTypedParameterAssignValue(par, VIR_TYPED_PARAM_INT, value); va_start(ap, namefmt); - ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - return ret; + return 0; } @@ -868,15 +880,14 @@ virTypedParamListAddUInt(virTypedParamList *list, { virTypedParameterPtr par =3D virTypedParamListExtend(list); va_list ap; - int ret; virTypedParameterAssignValue(par, VIR_TYPED_PARAM_UINT, value); va_start(ap, namefmt); - ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - return ret; + return 0; } @@ -888,15 +899,14 @@ virTypedParamListAddLLong(virTypedParamList *list, { virTypedParameterPtr par =3D virTypedParamListExtend(list); va_list ap; - int ret; virTypedParameterAssignValue(par, VIR_TYPED_PARAM_LLONG, value); va_start(ap, namefmt); - ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - return ret; + return 0; } @@ -908,15 +918,14 @@ virTypedParamListAddULLong(virTypedParamList *list, { virTypedParameterPtr par =3D virTypedParamListExtend(list); va_list ap; - int ret; virTypedParameterAssignValue(par, VIR_TYPED_PARAM_ULLONG, value); va_start(ap, namefmt); - ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - return ret; + return 0; } @@ -928,15 +937,14 @@ virTypedParamListAddString(virTypedParamList *list, { virTypedParameterPtr par =3D virTypedParamListExtend(list); va_list ap; - int ret; virTypedParameterAssignValue(par, VIR_TYPED_PARAM_STRING, value); va_start(ap, namefmt); - ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - return ret; + return 0; } @@ -948,15 +956,14 @@ virTypedParamListAddBoolean(virTypedParamList *list, { virTypedParameterPtr par =3D virTypedParamListExtend(list); va_list ap; - int ret; virTypedParameterAssignValue(par, VIR_TYPED_PARAM_BOOLEAN, value); va_start(ap, namefmt); - ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - return ret; + return 0; } @@ -968,13 +975,12 @@ virTypedParamListAddDouble(virTypedParamList *list, { virTypedParameterPtr par =3D virTypedParamListExtend(list); va_list ap; - int ret; virTypedParameterAssignValue(par, VIR_TYPED_PARAM_DOUBLE, value); va_start(ap, namefmt); - ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - return ret; + return 0; } --=20 2.39.2