]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sort-util: add missing parens
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 5 Mar 2022 00:43:20 +0000 (09:43 +0900)
committerLennart Poettering <lennart@poettering.net>
Fri, 18 Mar 2022 08:42:38 +0000 (09:42 +0100)
With this, we can call e.g.
```
typesafe_qsort(buf + m, n - m, comp);
```

src/basic/sort-util.h

index 02a6784d99d109d1956ca6019a21838255bead98..f0bf246aa3af048831c39f56b0ec871a6552f775 100644 (file)
@@ -16,8 +16,8 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
 
 #define typesafe_bsearch_r(k, b, n, func, userdata)                     \
         ({                                                              \
-                const typeof(b[0]) *_k = k;                             \
-                int (*_func_)(const typeof(b[0])*, const typeof(b[0])*, typeof(userdata)) = func; \
+                const typeof((b)[0]) *_k = k;                           \
+                int (*_func_)(const typeof((b)[0])*, const typeof((b)[0])*, typeof(userdata)) = func; \
                 xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \
         })
 
@@ -36,8 +36,8 @@ static inline void* bsearch_safe(const void *key, const void *base,
 
 #define typesafe_bsearch(k, b, n, func)                                 \
         ({                                                              \
-                const typeof(b[0]) *_k = k;                             \
-                int (*_func_)(const typeof(b[0])*, const typeof(b[0])*) = func; \
+                const typeof((b)[0]) *_k = k;                           \
+                int (*_func_)(const typeof((b)[0])*, const typeof((b)[0])*) = func; \
                 bsearch_safe((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_fn_t) _func_); \
         })
 
@@ -57,7 +57,7 @@ static inline void _qsort_safe(void *base, size_t nmemb, size_t size, comparison
  * is the prototype for the comparison function */
 #define typesafe_qsort(p, n, func)                                      \
         ({                                                              \
-                int (*_func_)(const typeof(p[0])*, const typeof(p[0])*) = func; \
+                int (*_func_)(const typeof((p)[0])*, const typeof((p)[0])*) = func; \
                 _qsort_safe((p), (n), sizeof((p)[0]), (comparison_fn_t) _func_); \
         })
 
@@ -71,7 +71,7 @@ static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, compariso
 
 #define typesafe_qsort_r(p, n, func, userdata)                          \
         ({                                                              \
-                int (*_func_)(const typeof(p[0])*, const typeof(p[0])*, typeof(userdata)) = func; \
+                int (*_func_)(const typeof((p)[0])*, const typeof((p)[0])*, typeof(userdata)) = func; \
                 qsort_r_safe((p), (n), sizeof((p)[0]), (comparison_userdata_fn_t) _func_, userdata); \
         })