Skip to contentSkip to conversation

coccinelle: combine two rules from qsort.cocci

PATCH New Markus Elfring 1 participant 1 message Nov 12, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coccinelle: combine two rules from qsort.cocci

From: Markus Elfring <[email protected]>
Date: Tue, 12 Nov 2019 20:20:13 +0100

This script contained two transformation rules for the semantic patch language which used duplicate code.

* Reduce duplication by merging common code from these rules.

* Use a SmPL disjunction for the pointer determination according to a sizeof operator.

---
 contrib/coccinelle/qsort.cocci | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
contrib/coccinelle/qsort.cocci +5 -8
index 22b93a9966..1c9a12c7c0 100644
@@ -1,14 +1,11 @@
 @@
 expression base, nmemb, compar;
 @@
-- qsort(base, nmemb, sizeof(*base), compar);
-+ QSORT(base, nmemb, compar);
-
-@@
-expression base, nmemb, compar;
-@@
-- qsort(base, nmemb, sizeof(base[0]), compar);
-+ QSORT(base, nmemb, compar);
+-qsort
++QSORT
+      (base, nmemb,
+-      sizeof( \( *base \| base[0] \) ),
+       compar);
 
 @@
 type T;

--
2.24.0