From: Yu Watanabe Date: Tue, 18 Sep 2018 23:28:50 +0000 (+0900) Subject: busctl,sd-lldp: explicitly specify type of argument in compare function X-Git-Tag: v240~712^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F10112%2Fhead;p=thirdparty%2Fsystemd.git busctl,sd-lldp: explicitly specify type of argument in compare function Several functions are shared by qsort and hash_ops or Prioq. This makes these functions explicitly specify argument type, and cast to __compar_fn_t where necessary. --- diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 1fe6500ae84..7b651cfcd69 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -719,8 +719,7 @@ static void member_hash_func(const void *p, struct siphash *state) { string_hash_func(m->interface, state); } -static int member_compare_func(const void *a, const void *b) { - const Member *x = a, *y = b; +static int member_compare_func(const Member *x, const Member *y) { int d; assert(x); @@ -911,7 +910,7 @@ static int on_property(const char *interface, const char *name, const char *sign static int introspect(int argc, char **argv, void *userdata) { static const struct hash_ops member_hash_ops = { .hash = member_hash_func, - .compare = member_compare_func, + .compare = (__compar_fn_t) member_compare_func, }; static const XMLIntrospectOps ops = { diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index 8295d4d4040..f3c4e0ac881 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -18,8 +18,7 @@ static void lldp_neighbor_id_hash_func(const void *p, struct siphash *state) { siphash24_compress(&id->port_id_size, sizeof(id->port_id_size), state); } -static int lldp_neighbor_id_compare_func(const void *a, const void *b) { - const LLDPNeighborID *x = a, *y = b; +int lldp_neighbor_id_compare_func(const LLDPNeighborID *x, const LLDPNeighborID *y) { int r; r = memcmp(x->chassis_id, y->chassis_id, MIN(x->chassis_id_size, y->chassis_id_size)); @@ -39,7 +38,7 @@ static int lldp_neighbor_id_compare_func(const void *a, const void *b) { const struct hash_ops lldp_neighbor_id_hash_ops = { .hash = lldp_neighbor_id_hash_func, - .compare = lldp_neighbor_id_compare_func + .compare = (__compar_fn_t) lldp_neighbor_id_compare_func, }; int lldp_neighbor_prioq_compare_func(const void *a, const void *b) { diff --git a/src/libsystemd-network/lldp-neighbor.h b/src/libsystemd-network/lldp-neighbor.h index 494bc51760a..2241c3bd9df 100644 --- a/src/libsystemd-network/lldp-neighbor.h +++ b/src/libsystemd-network/lldp-neighbor.h @@ -81,6 +81,7 @@ static inline void* LLDP_NEIGHBOR_TLV_DATA(const sd_lldp_neighbor *n) { } extern const struct hash_ops lldp_neighbor_id_hash_ops; +int lldp_neighbor_id_compare_func(const LLDPNeighborID *x, const LLDPNeighborID *y); int lldp_neighbor_prioq_compare_func(const void *a, const void *b); sd_lldp_neighbor *lldp_neighbor_unlink(sd_lldp_neighbor *n); diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c index 4edcc6dff40..e60aebc6277 100644 --- a/src/libsystemd-network/sd-lldp.c +++ b/src/libsystemd-network/sd-lldp.c @@ -372,7 +372,7 @@ _public_ int sd_lldp_new(sd_lldp **ret) { } static int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_neighbor * const *b) { - return lldp_neighbor_id_hash_ops.compare(&(*a)->id, &(*b)->id); + return lldp_neighbor_id_compare_func(&(*a)->id, &(*b)->id); } static int on_timer_event(sd_event_source *s, uint64_t usec, void *userdata) {