From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bruce Richardson Subject: [PATCH 3/5] devtools/cocci: create safer version of strlcpy script Date: Wed, 3 Apr 2019 15:45:03 +0100 Message-ID: <20190403144505.46234-4-bruce.richardson@intel.com> References: <20190403144505.46234-1-bruce.richardson@intel.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Bruce Richardson To: dev@dpdk.org Return-path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 86ADB1B46F for ; Wed, 3 Apr 2019 16:45:27 +0200 (CEST) In-Reply-To: <20190403144505.46234-1-bruce.richardson@intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The existing cocci script for coccinelle replaces all matching instances of snprintf() with strlcpy() without regards to header inclusion. To allow changes without build errors, we create a safer version of this script that only makes changes when the rte_string_fns.h header is already included. Signed-off-by: Bruce Richardson --- devtools/cocci/strlcpy-with-header.cocci | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 devtools/cocci/strlcpy-with-header.cocci diff --git a/devtools/cocci/strlcpy-with-header.cocci b/devtools/cocci/strlcpy-with-header.cocci new file mode 100644 index 000000000..046cdbdad --- /dev/null +++ b/devtools/cocci/strlcpy-with-header.cocci @@ -0,0 +1,12 @@ +@include@ +@@ + +#include + +@use_strlcpy depends on include@ +expression src, dst, size; +@@ +( +- snprintf(dst, size, "%s", src) ++ strlcpy(dst, src, size) +) -- 2.20.1