mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-05 22:50:14 +00:00
tools: Add coccinelle script to catch memset/memcpy wrong usage
Wrong: memset(&a, 0, sizeof(struct ...)); Good: memset(&a, 0, sizeof(a)); Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
parent
b5605493a4
commit
ab2c896a97
21
tools/coccinelle/memset.cocci
Normal file
21
tools/coccinelle/memset.cocci
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
|
||||
@@
|
||||
identifier src, dst;
|
||||
identifier str, len;
|
||||
type t =~ "struct";
|
||||
|
||||
@@
|
||||
|
||||
(
|
||||
- memset(&dst, 0, sizeof(t));
|
||||
+ memset(&dst, 0, sizeof(dst));
|
||||
|
|
||||
- memcpy(&dst, &src, sizeof(t));
|
||||
+ memcpy(&dst, &src, sizeof(dst));
|
||||
|
|
||||
- char str[...];
|
||||
...
|
||||
- memset(&str, 0, ...);
|
||||
+ memset(&str, 0, sizeof(str));
|
||||
)
|
Loading…
Reference in New Issue
Block a user