Skip to content

Commit

Permalink
all: fix and enable "-Wsign-compare" warning
Browse files Browse the repository at this point in the history
  • Loading branch information
thom311 committed May 29, 2024
1 parent 9451842 commit 2af9e72
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 40 deletions.
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ warn_cppflags = \
-Wpointer-arith \
-Wvla \
\
-Wno-sign-compare \
-Wno-unused-parameter \
$(NULL)

Expand Down
2 changes: 1 addition & 1 deletion lib/fib_lookup/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ int flnl_lookup_build_request(struct flnl_request *req, int flags,
fr.fl_fwmark = fwmark != UINT_LEAST64_MAX ? fwmark : 0;
fr.fl_tos = tos >= 0 ? tos : 0;
fr.fl_scope = scope >= 0 ? scope : RT_SCOPE_UNIVERSE;
fr.tb_id_in = table >= 0 ? table : RT_TABLE_UNSPEC;
fr.tb_id_in = table >= 0 ? (unsigned)table : (unsigned)RT_TABLE_UNSPEC;

addr = flnl_request_get_addr(req);
if (!addr)
Expand Down
2 changes: 1 addition & 1 deletion lib/route/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ struct rtnl_addr *rtnl_addr_get(struct nl_cache *cache, int ifindex,
return NULL;

nl_list_for_each_entry(a, &cache->c_items, ce_list) {
if (ifindex && a->a_ifindex != ifindex)
if (ifindex != 0 && a->a_ifindex != ((unsigned)ifindex))
continue;

if (a->ce_mask & ADDR_ATTR_LOCAL &&
Expand Down
6 changes: 4 additions & 2 deletions lib/route/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ struct rtnl_class *rtnl_class_get(struct nl_cache *cache, int ifindex,
return NULL;

nl_list_for_each_entry(class, &cache->c_items, ce_list) {
if (class->c_handle == handle && class->c_ifindex == ifindex) {
if (class->c_handle == handle &&
class->c_ifindex == ((unsigned)ifindex)) {
nl_object_get((struct nl_object *) class);
return class;
}
Expand Down Expand Up @@ -390,7 +391,8 @@ struct rtnl_class *rtnl_class_get_by_parent(struct nl_cache *cache, int ifindex,
return NULL;

nl_list_for_each_entry(class, &cache->c_items, ce_list) {
if (class->c_parent == parent && class->c_ifindex == ifindex) {
if (class->c_parent == parent &&
class->c_ifindex == ((unsigned)ifindex)) {
nl_object_get((struct nl_object *) class);
return class;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/route/cls.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ struct rtnl_cls *rtnl_cls_find_by_handle(struct nl_cache *cache, int ifindex, ui

nl_list_for_each_entry(cls, &cache->c_items, ce_list) {
if ((cls->c_parent == parent) &&
(cls->c_ifindex == ifindex)&&
cls->c_ifindex == ((unsigned)ifindex) &&
(cls->c_handle == handle)) {
nl_object_get((struct nl_object *) cls);
return cls;
Expand Down Expand Up @@ -429,9 +429,9 @@ struct rtnl_cls *rtnl_cls_find_by_prio(struct nl_cache *cache, int ifindex,

nl_list_for_each_entry(cls, &cache->c_items, ce_list) {
if ((cls->c_parent == parent) &&
(cls->c_ifindex == ifindex) &&
cls->c_ifindex == ((unsigned)ifindex) &&
(cls->c_prio == prio)) {
nl_object_get((struct nl_object *) cls);
nl_object_get((struct nl_object *)cls);
return cls;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/route/cls/ematch.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ int rtnl_ematch_parse_attr(struct nlattr *attr, struct rtnl_ematch_tree **result
NL_DBG(3, "parsing ematch attribute %d, len=%u\n",
nmatches+1, nla_len(a));

if (nla_len(a) < sizeof(*hdr)) {
if (_nla_len(a) < sizeof(*hdr)) {
err = -NLE_INVAL;
goto errout;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/route/cls/u32.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static int u32_msg_parser(struct rtnl_tc *tc, void *data)
sel = u->cu_selector->d_data;
pcnt_size = sizeof(struct tc_u32_pcnt) +
(sel->nkeys * sizeof(uint64_t));
if (nla_len(tb[TCA_U32_PCNT]) < pcnt_size) {
if (_nla_len(tb[TCA_U32_PCNT]) < pcnt_size) {
err = -NLE_INVAL;
goto errout;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/route/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ int rtnl_link_info_parse(struct rtnl_link *link, struct nlattr **tb)
/* beware: @st might not be the full struct, only fields up to
* tx_compressed are present. See _nl_offsetofend() above. */

if (nla_len(tb[IFLA_STATS]) >= _nl_offsetofend (struct rtnl_link_stats, rx_nohandler))
if (_nla_len(tb[IFLA_STATS]) >= _nl_offsetofend (struct rtnl_link_stats, rx_nohandler))
link->l_stats[RTNL_LINK_RX_NOHANDLER] = st->rx_nohandler;
else
link->l_stats[RTNL_LINK_RX_NOHANDLER] = 0;
Expand Down Expand Up @@ -1320,7 +1320,7 @@ struct rtnl_link *rtnl_link_get(struct nl_cache *cache, int ifindex)
return NULL;

nl_list_for_each_entry(link, &cache->c_items, ce_list) {
if (link->l_index == ifindex) {
if (link->l_index == ((unsigned)ifindex)) {
nl_object_get((struct nl_object *) link);
return link;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/route/link/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static int can_parse(struct rtnl_link *link, struct nlattr *data,
ci->ci_mask |= CAN_HAS_DATA_BITTIMING_CONST;
}

if (xstats && nla_len(xstats) >= sizeof(ci->ci_device_stats)) {
if (xstats && _nla_len(xstats) >= sizeof(ci->ci_device_stats)) {
nla_memcpy(&ci->ci_device_stats, xstats, sizeof(ci->ci_device_stats));
ci->ci_mask |= CAN_HAS_DEVICE_STATS;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/route/link/macsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ static int macsec_compare(struct rtnl_link *link_a, struct rtnl_link *link_b,
struct macsec_info *a = link_a->l_info;
struct macsec_info *b = link_b->l_info;
int diff = 0;
uint32_t attrs = flags & LOOSE_COMPARISON ? b->ce_mask : ~0;
uint32_t attrs = flags & LOOSE_COMPARISON ? b->ce_mask :
~((uint32_t)0u);

#define _DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ATTR, a, b, EXPR)
if (a->ce_mask & MACSEC_ATTR_SCI && b->ce_mask & MACSEC_ATTR_SCI)
Expand Down
7 changes: 5 additions & 2 deletions lib/route/link/macvlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static int macvlan_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
{
struct macvlan_info *mvi = link->l_info;
struct nlattr *data, *datamac = NULL;
int i, ret;
int ret;

if (!(data = nla_nest_start(msg, IFLA_INFO_DATA)))
return -NLE_MSGSIZE;
Expand All @@ -239,6 +239,8 @@ static int macvlan_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
NLA_PUT_U16(msg, IFLA_MACVLAN_FLAGS, mvi->mvi_flags);

if (mvi->mvi_mask & MACVLAN_HAS_MACADDR) {
uint32_t i;

NLA_PUT_U32(msg, IFLA_MACVLAN_MACADDR_MODE, mvi->mvi_macmode);
datamac = nla_nest_start(msg, IFLA_MACVLAN_MACADDR_DATA);
if (!datamac)
Expand Down Expand Up @@ -345,14 +347,15 @@ int rtnl_link_is_macvlan(struct rtnl_link *link)
int rtnl_link_macvlan_set_mode(struct rtnl_link *link, uint32_t mode)
{
struct macvlan_info *mvi = link->l_info;
int i;

IS_MACVLAN_LINK_ASSERT(link);

mvi->mvi_mode = mode;
mvi->mvi_mask |= MACVLAN_HAS_MODE;

if (mode != MACVLAN_MODE_SOURCE) {
uint32_t i;

for (i = 0; i < mvi->mvi_maccount; i++)
nl_addr_put(mvi->mvi_macaddr[i]);
free(mvi->mvi_macaddr);
Expand Down
6 changes: 3 additions & 3 deletions lib/route/link/sriov.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ int rtnl_link_sriov_parse_vflist(struct rtnl_link *link, struct nlattr **tb) {
if (t[IFLA_VF_SPOOFCHK]) {
vf_spoofchk = nla_data(t[IFLA_VF_SPOOFCHK]);

if (vf_spoofchk->setting != -1) {
if (vf_spoofchk->setting != ((uint32_t)-1)) {
vf_data->vf_spoofchk = vf_spoofchk->setting ? 1 : 0;
vf_data->ce_mask |= SRIOV_ATTR_SPOOFCHK;
}
Expand Down Expand Up @@ -662,7 +662,7 @@ int rtnl_link_sriov_parse_vflist(struct rtnl_link *link, struct nlattr **tb) {
if (t[IFLA_VF_RSS_QUERY_EN]) {
vf_rss_query = nla_data(t[IFLA_VF_RSS_QUERY_EN]);

if (vf_rss_query->setting != -1) {
if (vf_rss_query->setting != ((uint32_t)-1)) {
vf_data->vf_rss_query_en = vf_rss_query->setting ? 1 : 0;
vf_data->ce_mask |= SRIOV_ATTR_RSS_QUERY_EN;
}
Expand Down Expand Up @@ -702,7 +702,7 @@ int rtnl_link_sriov_parse_vflist(struct rtnl_link *link, struct nlattr **tb) {
if (t[IFLA_VF_TRUST]) {
vf_trust = nla_data(t[IFLA_VF_TRUST]);

if (vf_trust->setting != -1) {
if (vf_trust->setting != ((uint32_t)-1)) {
vf_data->vf_trust = vf_trust->setting ? 1 : 0;
vf_data->ce_mask |= SRIOV_ATTR_TRUST;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/route/link/vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static int vlan_parse(struct rtnl_link *link, struct nlattr *data,
memset(vi->vi_ingress_qos, 0, sizeof(vi->vi_ingress_qos));

nla_for_each_nested(nla, tb[IFLA_VLAN_INGRESS_QOS], remaining) {
if (nla_len(nla) < sizeof(*map))
if (_nla_len(nla) < sizeof(*map))
return -NLE_INVAL;

map = nla_data(nla);
Expand Down Expand Up @@ -154,7 +154,7 @@ static int vlan_parse(struct rtnl_link *link, struct nlattr *data,
int remaining, i = 0;

nla_for_each_nested(nla, tb[IFLA_VLAN_EGRESS_QOS], remaining) {
if (nla_len(nla) < sizeof(*map))
if (_nla_len(nla) < sizeof(*map))
return -NLE_INVAL;
i++;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/route/link/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ static int vxlan_compare(struct rtnl_link *link_a, struct rtnl_link *link_b,
struct vxlan_info *a = link_a->l_info;
struct vxlan_info *b = link_b->l_info;
int diff = 0;
uint32_t attrs = flags & LOOSE_COMPARISON ? b->ce_mask : ~0;
uint32_t attrs = flags & LOOSE_COMPARISON ? b->ce_mask :
~((uint32_t)0u);

#define _DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ATTR, a, b, EXPR)
diff |= _DIFF(VXLAN_ATTR_ID, a->vxi_id != b->vxi_id);
Expand Down
12 changes: 6 additions & 6 deletions lib/route/neigh.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,8 @@ struct rtnl_neigh * rtnl_neigh_get(struct nl_cache *cache, int ifindex,
struct rtnl_neigh *neigh;

nl_list_for_each_entry(neigh, &cache->c_items, ce_list) {
if (neigh->n_ifindex == ifindex &&
neigh->n_family == dst->a_family &&
if (neigh->n_ifindex == ((unsigned)ifindex) &&
neigh->n_family == ((unsigned)dst->a_family) &&
!nl_addr_cmp(neigh->n_dst, dst)) {
nl_object_get((struct nl_object *) neigh);
return neigh;
Expand All @@ -702,9 +702,9 @@ struct rtnl_neigh * rtnl_neigh_get_by_vlan(struct nl_cache *cache, int ifindex,
struct rtnl_neigh *neigh;

nl_list_for_each_entry(neigh, &cache->c_items, ce_list) {
if (neigh->n_ifindex == ifindex &&
neigh->n_vlan == vlan &&
neigh->n_lladdr && !nl_addr_cmp(neigh->n_lladdr, lladdr)) {
if ((neigh->n_ifindex == (unsigned)ifindex) &&
neigh->n_vlan == vlan && neigh->n_lladdr &&
!nl_addr_cmp(neigh->n_lladdr, lladdr)) {
nl_object_get((struct nl_object *) neigh);
return neigh;
}
Expand Down Expand Up @@ -1012,7 +1012,7 @@ static inline int __assign_addr(struct rtnl_neigh *neigh, struct nl_addr **pos,
{
if (!nocheck) {
if (neigh->ce_mask & NEIGH_ATTR_FAMILY) {
if (new->a_family != neigh->n_family)
if (neigh->n_family != ((unsigned)new->a_family))
return -NLE_AF_MISMATCH;
} else {
neigh->n_family = new->a_family;
Expand Down
3 changes: 1 addition & 2 deletions lib/route/neightbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,7 @@ struct rtnl_neightbl *rtnl_neightbl_get(struct nl_cache *cache,

nl_list_for_each_entry(nt, &cache->c_items, ce_list) {
if (!strcasecmp(nt->nt_name, name) &&
((!ifindex && !nt->nt_parms.ntp_ifindex) ||
(ifindex && ifindex == nt->nt_parms.ntp_ifindex))) {
((unsigned)ifindex) == nt->nt_parms.ntp_ifindex) {
nl_object_get((struct nl_object *)nt);
return nt;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/route/nh.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ struct rtnl_nh *rtnl_nh_get(struct nl_cache *cache, int nhid)
return NULL;

nl_list_for_each_entry(nh, &cache->c_items, ce_list) {
if (nh->nh_id == nhid) {
if (nh->nh_id == ((unsigned)nhid)) {
nl_object_get((struct nl_object *)nh);
return nh;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/route/qdisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ struct rtnl_qdisc *rtnl_qdisc_get_by_parent(struct nl_cache *cache,
return NULL;

nl_list_for_each_entry(q, &cache->c_items, ce_list) {
if (q->q_parent == parent && q->q_ifindex == ifindex) {
if (q->q_parent == parent &&
q->q_ifindex == ((unsigned)ifindex)) {
nl_object_get((struct nl_object *) q);
return q;
}
Expand Down Expand Up @@ -420,7 +421,8 @@ struct rtnl_qdisc *rtnl_qdisc_get_by_kind(struct nl_cache *cache,
return NULL;

nl_list_for_each_entry(q, &cache->c_items, ce_list) {
if ((q->q_ifindex == ifindex) && (!strcmp(q->q_kind, kind))) {
if ((q->q_ifindex == ((unsigned)ifindex)) &&
(!strcmp(q->q_kind, kind))) {
nl_object_get((struct nl_object *) q);
return q;
}
Expand Down Expand Up @@ -452,7 +454,8 @@ struct rtnl_qdisc *rtnl_qdisc_get(struct nl_cache *cache, int ifindex,
return NULL;

nl_list_for_each_entry(q, &cache->c_items, ce_list) {
if (q->q_handle == handle && q->q_ifindex == ifindex) {
if (q->q_handle == handle &&
q->q_ifindex == ((unsigned)ifindex)) {
nl_object_get((struct nl_object *) q);
return q;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/route/qdisc/tbf.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ static int tbf_msg_fill(struct rtnl_tc *tc, void *data, struct nl_msg *msg)
uint32_t rtab[RTNL_TC_RTABLE_SIZE], ptab[RTNL_TC_RTABLE_SIZE];
struct tc_tbf_qopt opts;
struct rtnl_tbf *tbf = data;
int required = TBF_ATTR_RATE | TBF_ATTR_LIMIT;
const uint32_t REQUIRED = TBF_ATTR_RATE | TBF_ATTR_LIMIT;

if ((tbf->qt_mask & required) != required)
if ((tbf->qt_mask & REQUIRED) != REQUIRED)
return -NLE_MISSING_ATTR;

memset(&opts, 0, sizeof(opts));
Expand Down
8 changes: 5 additions & 3 deletions lib/route/route_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,9 +948,11 @@ void rtnl_route_foreach_nexthop(struct rtnl_route *r,
struct rtnl_nexthop *rtnl_route_nexthop_n(struct rtnl_route *r, int n)
{
struct rtnl_nexthop *nh;
uint32_t i;

if (r->ce_mask & ROUTE_ATTR_MULTIPATH && r->rt_nr_nh > n) {
if (r->ce_mask & ROUTE_ATTR_MULTIPATH && n >= 0 &&
((unsigned)n) < r->rt_nr_nh) {
int i;

i = 0;
nl_list_for_each_entry(nh, &r->rt_nexthops, rtnh_list) {
if (i == n) return nh;
Expand Down Expand Up @@ -1270,7 +1272,7 @@ int rtnl_route_parse(struct nlmsghdr *nlh, struct rtnl_route **result)
return err;

for (i = 1; i <= RTAX_MAX; i++) {
if (mtb[i] && nla_len(mtb[i]) >= sizeof(uint32_t)) {
if (mtb[i] && _nla_len(mtb[i]) >= sizeof(uint32_t)) {
uint32_t m = nla_get_u32(mtb[i]);

err = rtnl_route_set_metric(route, i, m);
Expand Down
2 changes: 1 addition & 1 deletion lib/route/tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ int rtnl_tc_calc_cell_log(int cell_size)
int i;

for (i = 0; i < 32; i++)
if ((((uint32_t)1u) << i) == cell_size)
if ((((uint32_t)1u) << i) == ((uint32_t)cell_size))
return i;

return -NLE_INVAL;
Expand Down

0 comments on commit 2af9e72

Please sign in to comment.