From nobody Tue May  6 13:30:14 2025
Delivered-To: importer@patchew.org
Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Authentication-Results: mx.zohomail.com;
	dkim=fail;
	spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted
 sender)  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=fail(p=none dis=none)  header.from=linaro.org
ARC-Seal: i=1; a=rsa-sha256; t=1556557461; cv=none;
	d=zoho.com; s=zohoarc;
	b=XvMTUyKjPrdBRB9qWHjUa3tIZRnWBgzpCcvkHIE3FBrVIx5yssEszfL0NiSamllybkwaLEa14h4Wju72U0ctWGmnwJeRXmLye78Q3c/Uf/7K2NfSAqTsqK4w47zPTZ9IjO2bpvJ3i6VSPGxYcbVRqJ6fMwhZgc2ywKYFBAaMSeI=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
 s=zohoarc;
	t=1556557461;
 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:ARC-Authentication-Results;
	bh=PoBbqKnm48icKHr+pnJggpSaSU4ZKCdGTaxhpvXU0VQ=;
	b=YTP3+a+R69e3xisv7oU9sHGlRHF3AhZG8XJ1L8pl0IfApPdVd0+OFfcpM4wbGRkQgIpYOPGtpcD3/fuLE201kyRQqd9LBEBTbAdxfrTAcvXR00f8qCCo2FkDZxcIezFPsLXRNiH2aytE8mKcSwFQlItrTBg0gaBGEuEzF2kM46c=
ARC-Authentication-Results: i=1; mx.zoho.com;
	dkim=fail;
	spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted
 sender)  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=fail header.from=<peter.maydell@linaro.org> (p=none dis=none)
 header.from=<peter.maydell@linaro.org>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1556557461334164.34909769732258;
 Mon, 29 Apr 2019 10:04:21 -0700 (PDT)
Received: from localhost ([127.0.0.1]:60621 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1hL9hO-0006qI-Bs
	for importer@patchew.org; Mon, 29 Apr 2019 13:04:14 -0400
Received: from eggs.gnu.org ([209.51.188.92]:34091)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <peter.maydell@linaro.org>) id 1hL9eB-0004DP-Ka
	for qemu-devel@nongnu.org; Mon, 29 Apr 2019 13:00:56 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <peter.maydell@linaro.org>) id 1hL9e6-0006PE-Oz
	for qemu-devel@nongnu.org; Mon, 29 Apr 2019 13:00:52 -0400
Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:34428)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
	(Exim 4.71) (envelope-from <peter.maydell@linaro.org>)
	id 1hL9e4-00069E-19
	for qemu-devel@nongnu.org; Mon, 29 Apr 2019 13:00:48 -0400
Received: by mail-wr1-x430.google.com with SMTP id v16so14710340wrp.1
	for <qemu-devel@nongnu.org>; Mon, 29 Apr 2019 10:00:36 -0700 (PDT)
Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148])
	by smtp.gmail.com with ESMTPSA id a13sm36896wmj.39.2019.04.29.10.00.34
	for <qemu-devel@nongnu.org>
	(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
	Mon, 29 Apr 2019 10:00:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;
	h=from:to:subject:date:message-id:in-reply-to:references:mime-version
	:content-transfer-encoding;
	bh=PoBbqKnm48icKHr+pnJggpSaSU4ZKCdGTaxhpvXU0VQ=;
	b=iJYgOnzHanS8MCyf/Y/TsyhGhNhp8j68clu7GSzxkV8oyNeseLQdQN2j6h2tpNu428
	tMJgG9tAwIJyWypDVL0m3M8m5uxisI4BK++pkqnj/BFNkWe9UouweFt7uUdWNqZPaBNU
	GrTsYbXNg3p9cvoM/1f05Z/1rbvdtYK1WwknUBdbA7cCwjv4dyAsysyBh/Fu35/W+wLa
	2FCIcu7uHQ8jNGBlgbjpH5Sx0dZfInLkrp2l4HXipqSwUV8ks6EPRUFLcUcLu3C6lNF2
	+lboKxs6Wu8lvz2YWaG2vZVyiaEiLmtfxdqX+pmSk70urzxEPQeqhcEuSWYkigVgn70M
	m6Eg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
	:references:mime-version:content-transfer-encoding;
	bh=PoBbqKnm48icKHr+pnJggpSaSU4ZKCdGTaxhpvXU0VQ=;
	b=g5r6EJyAIAC0CaVmsqwQvMlMAXFLrChPAruHlylFJgIkz3AraZBg56p3/vSEe3ssMG
	t8ljKC49TZXSjOx0mCYsLDHjS5Oylq2SAaB7d+D59K/k40iTSGv4hgGbAWHQ2F69kguo
	OgjcPJSI3Lbdtvzf3twrSpH5rmMk2gwDKz8sZEp3AoXkonLnwYNrFJ927/898e83/po/
	iVt804+IkNQ1RYLXd6QymDgEbdNUFFtxxKbKOhsm69qyXZ/TYg6LTvvLHqAjQxEJBzur
	K/sW3IN025h86cHOeLRW5OJL6xqW7H0Js2eZoj0F4ube9hIeSdmuHAUcrteNez9vf/mE
	aVTA==
X-Gm-Message-State: APjAAAX59OWf0uMrnie6DZvV6NQ47kRNdELOFNl551teCO6ZigH+JqZS
	12oaIfxVrsgY5eOxyhhXJM2bfdA2V5E=
X-Google-Smtp-Source: 
 APXvYqwFfkZebByq1LtSNfImSnhxYhHdNH0ZZTRptRdaE5tiXQ6g+wYUybsaLQZuT1uI/IlCFmzQSQ==
X-Received: by 2002:a5d:410f:: with SMTP id l15mr15384783wrp.6.1556557235470;
	Mon, 29 Apr 2019 10:00:35 -0700 (PDT)
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Date: Mon, 29 Apr 2019 17:59:50 +0100
Message-Id: <20190429170030.11323-3-peter.maydell@linaro.org>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20190429170030.11323-1-peter.maydell@linaro.org>
References: <20190429170030.11323-1-peter.maydell@linaro.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 2a00:1450:4864:20::430
Subject: [Qemu-devel] [PULL 02/42] hw/ssi/xilinx_spips: Avoid variable
 length array
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
	<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <http://lists.nongnu.org/archive/html/qemu-devel/>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
	<mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: fail (Header signature does not verify)

In the stripe8() function we use a variable length array; however
we know that the maximum length required is MAX_NUM_BUSSES. Use
a fixed-length array and an assert instead.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daud=C3=A9 <f4bug@amsat.org>
Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Message-id: 20190328152635.2794-1-peter.maydell@linaro.org
---
 hw/ssi/xilinx_spips.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c
index 16f88f74029..c615058cc1b 100644
--- a/hw/ssi/xilinx_spips.c
+++ b/hw/ssi/xilinx_spips.c
@@ -429,12 +429,14 @@ static void xlnx_zynqmp_qspips_reset(DeviceState *d)
=20
 static inline void stripe8(uint8_t *x, int num, bool dir)
 {
-    uint8_t r[num];
-    memset(r, 0, sizeof(uint8_t) * num);
+    uint8_t r[MAX_NUM_BUSSES];
     int idx[2] =3D {0, 0};
     int bit[2] =3D {0, 7};
     int d =3D dir;
=20
+    assert(num <=3D MAX_NUM_BUSSES);
+    memset(r, 0, sizeof(uint8_t) * num);
+
     for (idx[0] =3D 0; idx[0] < num; ++idx[0]) {
         for (bit[0] =3D 7; bit[0] >=3D 0; bit[0]--) {
             r[idx[!d]] |=3D x[idx[d]] & 1 << bit[d] ? 1 << bit[!d] : 0;
--=20
2.20.1