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 E34B24331D;
	Mon, 13 Nov 2023 18:06:36 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 8B50940DDA;
	Mon, 13 Nov 2023 18:06:22 +0100 (CET)
Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com
 [209.85.214.178])
 by mails.dpdk.org (Postfix) with ESMTP id 50A4040A7F
 for <dev@dpdk.org>; Mon, 13 Nov 2023 18:06:19 +0100 (CET)
Received: by mail-pl1-f178.google.com with SMTP id
 d9443c01a7336-1cc68c1fac2so41235165ad.0
 for <dev@dpdk.org>; Mon, 13 Nov 2023 09:06:19 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1699895178;
 x=1700499978; darn=dpdk.org; 
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=uxAfJ8vzwr1WQklSqEm+Tn8oVVCx3fo3M3Y1fw61Dbk=;
 b=oTBcDuzhKMfQ+zpnRFmbOpyFBqwDmhye+TW7gz1RjiKsvE4kRhmhZDbYImeud1gUeZ
 SuyP+xRn2S0d+b11VpiOlR0PFQE/U4zGL0SMPBwBXPQYJqdg3huP7/VAAHyIhKfYWHUJ
 aL8UnQ0slMBQ7+pU/UuX/Eb/RbT0S7pXyMBMXB4IKxIgleVMgy5k0wAYuWf3OvLl/Y/L
 hbFm2UbHoQ5nQkyxahlSl9fBZn4aGVO9pQzryyvgX8GJT31C1rjp+Hxn3WsLlqUQ7z/u
 UJoGod4kJ4df3+Qf8WU/RgvfsS7FAIIQFsMFwUIFg+Z7aL1+hF8BkwToT0AB8k54N+Ox
 5Qpw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1699895178; x=1700499978;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=uxAfJ8vzwr1WQklSqEm+Tn8oVVCx3fo3M3Y1fw61Dbk=;
 b=XEFLTB6LvvwKVt0mf1De956ib5qilVSXHzt9oFSe4cAfM5Ns6FW5RlGpomQOvHKTS5
 0QVOAzB3nhv8RadkvWYGCnH4aHu+sIthWpuazNkWjhwWc2Ez0eIJvRiYD+nF5Z/WSx++
 Ll9g+f3FyWMcMnqkhssDiuHGad2ZN1XsKO1slRhuH0a+2KRljPSA/ohwPipRWgGekKqT
 7bFuj6gFw8lmYCTOjybbGOlE9cLKFdrRthBdugPytu0JUDMma1lb9XD1UgANfCZ9o11x
 yn4eWpR7pj2yM2kWMzCAes5RVb91NGb+hZMqkutQa+WW9uhOEsuIfdOO5FTgoOc3NUNe
 a3Lw==
X-Gm-Message-State: AOJu0YxlYk0sVrJTKaWnoaxPfc6iYTxi1RE4WApWo4Vcsrhy/NsROgIl
 /HYERJv2To2VsLIaKbSWNDn3oDxz1Lq6jDRg2MU=
X-Google-Smtp-Source: AGHT+IFSev4AIALLL5RjGSCN3tKRu0FNAqquV/Bm1UPyo1InUaV83jjm8OgAff4v7FydUo4Xpk1Nqw==
X-Received: by 2002:a17:902:ab89:b0:1cc:5e1b:98b5 with SMTP id
 f9-20020a170902ab8900b001cc5e1b98b5mr116768plr.66.1699895178214; 
 Mon, 13 Nov 2023 09:06:18 -0800 (PST)
Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141])
 by smtp.gmail.com with ESMTPSA id
 l4-20020a170902eb0400b001c61901ed2esm4232051plb.219.2023.11.13.09.06.17
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 13 Nov 2023 09:06:17 -0800 (PST)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
 =?UTF-8?q?Morten=20Br=C3=B8rup?= <mb@smartsharesystems.com>,
 Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH v2 3/3] eal: replace out of bounds VLA with static_assert
Date: Mon, 13 Nov 2023 09:06:05 -0800
Message-Id: <20231113170605.408281-4-stephen@networkplumber.org>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20231113170605.408281-1-stephen@networkplumber.org>
References: <20231111172153.57461-1-stephen@networkplumber.org>
 <20231113170605.408281-1-stephen@networkplumber.org>
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

Both Gcc, clang and MSVC have better way to do compile time
assertions rather than using out of bounds array access.
The old method would fail if -Wvla is enabled because compiler
can't determine size in that code.  Also, the use of new
_Static_assert will catch broken code that is passing non-constant
expression to RTE_BUILD_BUG_ON().

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/eal/include/rte_common.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index c1ba32d00e47..bea7c0e57d5e 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -16,6 +16,7 @@
 extern "C" {
 #endif
 
+#include <assert.h>
 #include <stdint.h>
 #include <limits.h>
 
@@ -495,7 +496,7 @@ rte_is_aligned(const void * const __rte_restrict ptr, const unsigned int align)
 /**
  * Triggers an error at compilation time if the condition is true.
  */
-#define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+#define RTE_BUILD_BUG_ON(condition) static_assert(!(condition), #condition)
 
 /*********** Cache line related macros ********/
 
-- 
2.39.2