From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id F1E4EA055C;
	Fri,  3 Jun 2022 13:16:34 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id C19C14069D;
	Fri,  3 Jun 2022 13:16:34 +0200 (CEST)
Received: from mga04.intel.com (mga04.intel.com [192.55.52.120])
 by mails.dpdk.org (Postfix) with ESMTP id 10B3D4069D
 for <dev@dpdk.org>; Fri,  3 Jun 2022 13:16:33 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1654254994; x=1685790994;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=NQZdqjgh0cgGEjC1upK0m2bYgLHTgQbGDXJAvlFJK4c=;
 b=hDVeEuC6jkRjyPfEm7tVBqLZkuzdW7+ZUEV0CCQZ8TM+cvLKXPd3Pydy
 ENR7wBlMc38CavA6txxJyKdJx2GwE8E2/IA68AuKaAEWdGqGNcWT6x/3V
 8aUR1ip+KznpcQkYiiDdSenLNxO2/jLfSVNuxm+tz7460XQVBXeFU7/uN
 usyf1HbMywflvlNaE2jIunZieUtpQAtuhOx3EphDKxXDOkYnhOOZkuT9j
 Jl4RROH560DYdBCIs87QYmZBL0n9MlSeogPDBk8Zivnnnke+r5xmzD7jU
 C9BQencguS+c+07hngdI4jRCVgzc0/wIyL7J8I2gyDiJxlgZwnGQjQCat Q==;
X-IronPort-AV: E=McAfee;i="6400,9594,10366"; a="275031087"
X-IronPort-AV: E=Sophos;i="5.91,274,1647327600"; d="scan'208";a="275031087"
Received: from orsmga008.jf.intel.com ([10.7.209.65])
 by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 03 Jun 2022 04:16:33 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.91,274,1647327600"; d="scan'208";a="607356401"
Received: from silpixa00401385.ir.intel.com (HELO
 silpixa00401385.ger.corp.intel.com) ([10.237.222.171])
 by orsmga008.jf.intel.com with ESMTP; 03 Jun 2022 04:16:31 -0700
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: david.marchand@redhat.com, Bruce Richardson <bruce.richardson@intel.com>,
 =?UTF-8?q?Morten=20Br=C3=B8rup?= <mb@smartsharesystems.com>,
 Stephen Hemminger <stephen@networkplumber.org>,
 Hemant Agrawal <hemant.agrawal@nxp.com>
Subject: [PATCH v4 1/4] cocci: add script for zero-length arrays in structs
Date: Fri,  3 Jun 2022 12:16:22 +0100
Message-Id: <20220603111625.562070-2-bruce.richardson@intel.com>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20220603111625.562070-1-bruce.richardson@intel.com>
References: <20220602150834.643745-1-bruce.richardson@intel.com>
 <20220603111625.562070-1-bruce.richardson@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Add script to replace [0] with [] when used at the end of a struct.
The script also includes an additional struct member to match against so
as to avoid issues with arrays with only a single zero-length element.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
 devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 devtools/cocci/zero_length_array.cocci

diff --git a/devtools/cocci/zero_length_array.cocci b/devtools/cocci/zero_length_array.cocci
new file mode 100644
index 0000000000..de8783bc7a
--- /dev/null
+++ b/devtools/cocci/zero_length_array.cocci
@@ -0,0 +1,21 @@
+// Replace zero-length array members with []
+@@
+identifier st, member, arr;
+type T1, T2;
+@@
+struct st {
+	...
+	T1 member;
+-	T2 arr[0];
++	T2 arr[];
+};
+@@
+identifier st, member, arr, id;
+type T1, T2;
+@@
+struct st {
+	...
+	T1 member;
+-	T2 arr[0];
++	T2 arr[];
+} id;
-- 
2.34.1