Re: coccinelle: adjustments for array.cocci?
From: Markus Elfring <hidden>
Date: 2019-11-15 20:37:44
This eliminates duplication in the semantic patch, which is good.
Thanks that you think in such a direction.
It messes up the indentation of n in some of the cases in 921d49be86 ("use
COPY_ARRAY for copying arrays", 2019-06-15), though. Hmm, but that can
be cured by duplicating the comma:
I have picked up further improvement possibilities for this SmPL script.
Would you like to integrate any of these changes?
@@
expression dst, src, n, E;
@@
memcpy(dst, src, sizeof(
+ *(
E
- [...]
+ )
) * n
)
@@
type T;
T *ptr;
T[] arr;
expression E, n;
@@
memcpy(
( ptr, E, sizeof(
- *(ptr)
+ T
) * n
| arr, E, sizeof(
- *(arr)
+ T
) * n
| E, ptr, sizeof(
- *(ptr)
+ T
) * n
| E, arr, sizeof(
- *(arr)
+ T
) * n
)
)
@@
type T;
T* dst_ptr, src_ptr;
T[] dst_arr, src_arr;
expression n, x;
@@
-memcpy
+COPY_ARRAY
(
( dst_ptr
| dst_arr
)
,
( src_ptr
| src_arr
)
- , (n) * \( sizeof(T) \| sizeof(*(x)) \)
+ , n
)
@@
type T;
T* dst, src, ptr;
expression n;
@@
(
-memmove
+MOVE_ARRAY
(dst, src
- , (n) * \( sizeof(* \( dst \| src \) ) \| sizeof(T) \)
+ , n
)
|
-ptr = xmalloc((n) * \( sizeof(*ptr) \| sizeof(T) \))
+ALLOC_ARRAY(ptr, n)
);
Now I observe that the placement of space characters can be a coding style
concern at four places for adjusted lines by the generated patch.
Would you like to clarify remaining issues for pretty-printing
in such use cases?
Regards,
Markus