From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id EF3CB1B93F for ; Fri, 14 Dec 2018 21:44:25 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Dec 2018 12:44:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,354,1539673200"; d="scan'208";a="101623743" Received: from ae13-28.jf.intel.com ([10.166.188.62]) by orsmga008.jf.intel.com with ESMTP; 14 Dec 2018 12:44:24 -0800 From: Jeff Shaw To: dev@dpdk.org Cc: mattias.ronnblom@ericsson.com, stephen@networkplumber.org, jeffrey.b.shaw@intel.com Date: Fri, 14 Dec 2018 12:40:42 -0800 Message-Id: <20181214204042.6435-1-jeffrey.b.shaw@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181214163827.9403-1-jeffrey.b.shaw@intel.com> References: <20181214163827.9403-1-jeffrey.b.shaw@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] eal: remove variable length array X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Dec 2018 20:44:26 -0000 Compilers that do not support the C99 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 --- V2: - Reference C99 in commit message instead of C11. - Remove unnecessary cast of alloca() returning void *. --- 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..6d7a220b0 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 = 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