[3/5] devtools/cocci: create safer version of strlcpy script

Message ID 20190403144505.46234-4-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series clean up snprintf use for string copying |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Bruce Richardson April 3, 2019, 2:45 p.m. UTC
  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 <bruce.richardson@intel.com>
---
 devtools/cocci/strlcpy-with-header.cocci | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 devtools/cocci/strlcpy-with-header.cocci
  

Patch

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 <rte_string_fns.h>
+
+@use_strlcpy depends on include@
+expression src, dst, size;
+@@
+(
+- snprintf(dst, size, "%s", src)
++ strlcpy(dst, src, size)
+)