[01/32] devtools/cocci: prefer structure assignment over memcpy

Message ID 20250208203142.242284-2-stephen@networkplumber.org (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series Use structure assignment instead of memcpy |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Feb. 8, 2025, 8:21 p.m. UTC
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@networkplumber.org>
---
 devtools/cocci/struct-assign.cocci | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 devtools/cocci/struct-assign.cocci
  

Patch

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
+)