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:
Donatas Abraitis 2022-05-11 13:12:22 +03:00
parent b5605493a4
commit ab2c896a97

View 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));
)