[PATCH 01/32] devtools/cocci: prefer structure assignment over memcpy
Stephen Hemminger
stephen at networkplumber.org
Sat Feb 8 21:21:53 CET 2025
Prefer using simple structure assignment instead of memcpy.
Using a structure assignment preserves type information and
compiler checks types already.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
devtools/cocci/struct-assign.cocci | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 devtools/cocci/struct-assign.cocci
diff --git a/devtools/cocci/struct-assign.cocci b/devtools/cocci/struct-assign.cocci
new file mode 100644
index 0000000000..052ebf3340
--- /dev/null
+++ b/devtools/cocci/struct-assign.cocci
@@ -0,0 +1,15 @@
+//
+// prefer structure assignment over memcpy
+//
+@@
+type T;
+T *SRCP;
+T *DSTP;
+@@
+(
+- rte_memcpy(DSTP, SRCP, sizeof(T))
++ *DSTP = *SRCP
+|
+- memcpy(DSTP, SRCP, sizeof(T))
++ *DSTP = *SRCP
+)
--
2.47.2
More information about the dev
mailing list