DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal: remove variable length array
@ 2018-12-14 16:38 Jeff Shaw
  2018-12-14 18:36 ` Stephen Hemminger
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Jeff Shaw @ 2018-12-14 16:38 UTC (permalink / raw)
  To: dev; +Cc: jeffrey.b.shaw

Compilers that do not support the C11 standard, or do not implement
gcc extensions, may not support variable length arrays.

The code prior to this commit produced the following warning when
compiled with "-Wvla -std=c90".

  warning: ISO C90 forbids variable length array ‘array’ [-Wvla]

This commit removes the variable length array from the PMD debug
trace function by allocating memory dynamically on the stack using
alloca().

Signed-off-by: Jeff Shaw <jeffrey.b.shaw@intel.com>
---
 lib/librte_eal/common/include/rte_dev.h | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index a9724dc91..af772872b 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -47,22 +47,21 @@ __attribute__((format(printf, 2, 0)))
 static inline void
 rte_pmd_debug_trace(const char *func_name, const char *fmt, ...)
 {
+	char *buffer;
+	int buf_len;
 	va_list ap;
 
 	va_start(ap, fmt);
+	buf_len = vsnprintf(NULL, 0, fmt, ap) + 1;
+	va_end(ap);
 
-	{
-		char buffer[vsnprintf(NULL, 0, fmt, ap) + 1];
+	buffer = (char *)alloca(buf_len);
 
-		va_end(ap);
-
-		va_start(ap, fmt);
-		vsnprintf(buffer, sizeof(buffer), fmt, ap);
-		va_end(ap);
+	va_start(ap, fmt);
+	vsnprintf(buffer, buf_len, fmt, ap);
+	va_end(ap);
 
-		rte_log(RTE_LOG_ERR, RTE_LOGTYPE_PMD, "%s: %s",
-			func_name, buffer);
-	}
+	rte_log(RTE_LOG_ERR, RTE_LOGTYPE_PMD, "%s: %s", func_name, buffer);
 }
 
 /*
-- 
2.14.3

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2018-12-22  0:37 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-14 16:38 [dpdk-dev] [PATCH] eal: remove variable length array Jeff Shaw
2018-12-14 18:36 ` Stephen Hemminger
2018-12-14 18:59   ` Jeff Shaw
2018-12-14 19:17     ` Jeff Shaw
2018-12-14 18:36 ` Mattias Rönnblom
2018-12-14 19:07   ` Jeff Shaw
2018-12-14 20:28     ` Mattias Rönnblom
2018-12-14 20:50       ` [dpdk-dev] [PATCH] eal: simplify RTE_PMD_DEBUG_TRACE Stephen Hemminger
2018-12-14 21:20         ` Jeff Shaw
2018-12-14 21:57           ` Stephen Hemminger
2018-12-21 16:17           ` Ferruh Yigit
2018-12-21 18:11         ` [dpdk-dev] [PATCH v2] " Jeff Shaw
2018-12-21 18:18           ` [dpdk-dev] [PATCH v3] " Jeff Shaw
2018-12-22  0:37             ` Ferruh Yigit
2018-12-19 21:45       ` [dpdk-dev] [PATCH] eal: remove variable length array Thomas Monjalon
2018-12-20 10:53         ` Mattias Rönnblom
2018-12-20 11:03           ` Thomas Monjalon
2018-12-14 20:40 ` [dpdk-dev] [PATCH v2] " Jeff Shaw
2018-12-15 14:26   ` Wiles, Keith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).