From nobody Mon Feb 9 00:30:10 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=1614696620; cv=none; d=zohomail.com; s=zohoarc; b=SzGUccje2y5mWHs7sFk539fnpT0XCGwfCgqTkzOLUW9tYqva0r2PlqOtb7hIMoahFBIkMR3Vv7NY5p7MV1K7lMjUXt3MDEJdvkEzbw+camazMo9XGlRgjtpDph+h25gQFhzUhwd9Dfx6YjH9jSMbYd0LQotKSpitd1QWCe2HX7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696620; 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=6Ui8n/UluthRYsf5u3OpzPlZbnzadN1/D+7eEe6JgJY=; b=iJx47L8xWyaeqnEdIAeZYhXO6vo1pFPqqPrRuZCPGcepLVEzeDoe2fKNoG81T0PzSYcXI2SRAzHYluhcS8dJgz+fB/OWzF9uFzajmECAuZrbr9CY+V0dNQ33Lpa7joNXfMTv+Ai4S7uNPzCn77qETQzwykfbYP4/7vK5JiS1EBE= 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 1614696620358948.4871693529622; Tue, 2 Mar 2021 06:50:20 -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-470-Gga_GUIMMfyXYok136h22w-1; Tue, 02 Mar 2021 09:50:16 -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 E8E3650753; Tue, 2 Mar 2021 14:50:09 +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 C301068D22; Tue, 2 Mar 2021 14:50:09 +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 871CC58080; Tue, 2 Mar 2021 14:50:09 +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 122Enm8d014506 for ; Tue, 2 Mar 2021 09:49:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 641835D723; Tue, 2 Mar 2021 14:49:48 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95EAF5D722 for ; Tue, 2 Mar 2021 14:49:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696619; 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=6Ui8n/UluthRYsf5u3OpzPlZbnzadN1/D+7eEe6JgJY=; b=SjcA1fwY8mVrh8SGHpeqkgrW+3oYiG8m4PrpCs4UDJEn0TrMafDGgjJbs1brLZ6JBo5Zvl kHQhuyXNGMYP7ISiUnIffoLy8foyBqCCAQWbaLZJft22AF82SN2pZDz7kQU9Sj1m2HhcE7 4X2kcN5IcdYtRaB2rHOpG2O3kfnWabQ= X-MC-Unique: Gga_GUIMMfyXYok136h22w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/16] xenParseSxprSound: Refactor parsing of model list Date: Tue, 2 Mar 2021 15:49:26 +0100 Message-Id: <71d05c6643cc7c532d1a89941bef9800b6e0f7e2.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.16 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" Copy the input string so that we don't have to use a static buffer and virStrncpy. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libxl/xen_common.c | 46 +++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 09c74dcb53..1c71f69209 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -1332,38 +1332,30 @@ xenParseSxprSound(virDomainDefPtr def, def->sounds[def->nsounds++] =3D sound; } } else { - char model[10]; - const char *offset =3D str, *offset2; - - do { - int len; - virDomainSoundDefPtr sound; - offset2 =3D strchr(offset, ','); - if (offset2) - len =3D (offset2 - offset); - else - len =3D strlen(offset); - if (virStrncpy(model, offset, len, sizeof(model)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Sound model %s too big for destination"), - offset); - return -1; - } + g_autofree char *sounds =3D g_strdup(str); + char *sound =3D sounds; + int model; - sound =3D g_new0(virDomainSoundDef, 1); + while (*sound !=3D '\0') { + char *next =3D strchr(sound, ','); + virDomainSoundDefPtr snddef; - if ((sound->model =3D virDomainSoundModelTypeFromString(model)= ) < 0) { - VIR_FREE(sound); - return -1; - } + if (next) + *next =3D '\0'; - if (VIR_APPEND_ELEMENT(def->sounds, def->nsounds, sound) < 0) { - virDomainSoundDefFree(sound); + if ((model =3D virDomainSoundModelTypeFromString(sound)) < 0) return -1; - } - offset =3D offset2 ? offset2 + 1 : NULL; - } while (offset); + snddef =3D g_new0(virDomainSoundDef, 1); + snddef->model =3D model; + + ignore_value(VIR_APPEND_ELEMENT(def->sounds, def->nsounds, snd= def)); + + if (!next) + break; + + sound =3D next + 1; + } } return 0; --=20 2.29.2