summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorКоренберг Марк <mark@ideco.ru>2012-06-08 20:15:06 +0600
committerThomas Graf <tgraf@redhat.com>2012-06-13 13:30:26 +0200
commit2bdcde7e8e8bb78b165f093f1a708134f417e557 (patch)
tree52d56b1b1d1f75373a33c27988ded96e6a62e36e
parent4f933648622fff2b7fd6ec6c71724da4992c2544 (diff)
downloadlibnl-2bdcde7e8e8bb78b165f093f1a708134f417e557.tar.gz
Fix types-related warnings based on clang diagnostics
1. Fix some places where unsigned value compared < 0 2. Fix obsolete %Z specifier to more portable %z 3. Some erroneous types substitution 4. nl_msec2str() - 64-bit msec is now properly used, Only safe changes. I mean int <--> uint32_t and signed/unsigned fixes. Some functinos require size_t argument instead of int, but changes of signatures of that functions is terrible thing. Also, I do not pretend for a full list of fixes. Just to shut up clang -Wall -Wextra One more thing. ifindex. I don't change that because changes will be too big for simple fix.
-rw-r--r--lib/addr.c6
-rw-r--r--lib/attr.c3
-rw-r--r--lib/data.c3
-rw-r--r--lib/genl/genl.c4
-rw-r--r--lib/msg.c8
-rw-r--r--lib/nl.c2
-rw-r--r--lib/object.c4
-rw-r--r--lib/route/addr.c4
-rw-r--r--lib/route/class.c4
-rw-r--r--lib/route/classid.c3
-rw-r--r--lib/route/cls.c4
-rw-r--r--lib/route/cls/u32.c2
-rw-r--r--lib/route/link/vlan.c7
-rw-r--r--lib/route/qdisc.c2
-rw-r--r--lib/route/qdisc/netem.c3
-rw-r--r--lib/route/route_obj.c2
-rw-r--r--lib/utils.c39
-rw-r--r--src/lib/route.c14
18 files changed, 63 insertions, 51 deletions
diff --git a/lib/addr.c b/lib/addr.c
index 89d3d4f..3acd9e4 100644
--- a/lib/addr.c
+++ b/lib/addr.c
@@ -368,7 +368,7 @@ int nl_addr_parse(const char *addrstr, int hint, struct nl_addr **result)
}
if (hint == AF_UNSPEC && strchr(str, ':')) {
- int i = 0;
+ size_t i = 0;
char *s = str, *p;
for (;;) {
long l = strtol(s, &p, 16);
@@ -542,7 +542,7 @@ int nl_addr_cmp_prefix(struct nl_addr *a, struct nl_addr *b)
*/
int nl_addr_iszero(struct nl_addr *addr)
{
- int i;
+ unsigned int i;
for (i = 0; i < addr->a_len; i++)
if (addr->a_addr[i])
@@ -823,7 +823,7 @@ unsigned int nl_addr_get_prefixlen(struct nl_addr *addr)
*/
char *nl_addr2str(struct nl_addr *addr, char *buf, size_t size)
{
- int i;
+ unsigned int i;
char tmp[16];
if (!addr || !addr->a_len) {
diff --git a/lib/attr.c b/lib/attr.c
index 6ef6cd9..a095649 100644
--- a/lib/attr.c
+++ b/lib/attr.c
@@ -188,7 +188,8 @@ static int validate_nla(struct nlattr *nla, int maxtype,
struct nla_policy *policy)
{
struct nla_policy *pt;
- int minlen = 0, type = nla_type(nla);
+ unsigned int minlen = 0;
+ int type = nla_type(nla);
if (type <= 0 || type > maxtype)
return 0;
diff --git a/lib/data.c b/lib/data.c
index e4196b1..f019539 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -110,9 +110,6 @@ struct nl_data *nl_data_clone(struct nl_data *src)
*/
int nl_data_append(struct nl_data *data, void *buf, size_t size)
{
- if (size < 0)
- BUG();
-
if (size > 0) {
data->d_data = realloc(data->d_data, data->d_size + size);
if (!data->d_data)
diff --git a/lib/genl/genl.c b/lib/genl/genl.c
index 569ef9e..8d3def3 100644
--- a/lib/genl/genl.c
+++ b/lib/genl/genl.c
@@ -223,9 +223,9 @@ struct genlmsghdr *genlmsg_hdr(struct nlmsghdr *nlh)
*/
int genlmsg_len(const struct genlmsghdr *gnlh)
{
- struct nlmsghdr *nlh;
+ const struct nlmsghdr *nlh;
- nlh = (struct nlmsghdr *)((unsigned char *) gnlh - NLMSG_HDRLEN);
+ nlh = (const struct nlmsghdr *)((const unsigned char *) gnlh - NLMSG_HDRLEN);
return (nlh->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN);
}
diff --git a/lib/msg.c b/lib/msg.c
index 18174b5..0adc091 100644
--- a/lib/msg.c
+++ b/lib/msg.c
@@ -178,7 +178,7 @@ int nlmsg_valid_hdr(const struct nlmsghdr *nlh, int hdrlen)
*/
int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
{
- return (remaining >= (int)sizeof(struct nlmsghdr) &&
+ return (remaining >= sizeof(struct nlmsghdr) &&
nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
nlh->nlmsg_len <= remaining);
}
@@ -867,7 +867,7 @@ void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
"-------------------------- BEGIN NETLINK MESSAGE "
"---------------------------\n");
- fprintf(ofd, " [HEADER] %Zu octets\n", sizeof(struct nlmsghdr));
+ fprintf(ofd, " [HEADER] %zu octets\n", sizeof(struct nlmsghdr));
print_hdr(ofd, msg);
if (hdr->nlmsg_type == NLMSG_ERROR &&
@@ -875,10 +875,10 @@ void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
struct nl_msg *errmsg;
struct nlmsgerr *err = nlmsg_data(hdr);
- fprintf(ofd, " [ERRORMSG] %Zu octets\n", sizeof(*err));
+ fprintf(ofd, " [ERRORMSG] %zu octets\n", sizeof(*err));
fprintf(ofd, " .error = %d \"%s\"\n", err->error,
strerror(-err->error));
- fprintf(ofd, " [ORIGINAL MESSAGE] %Zu octets\n", sizeof(*hdr));
+ fprintf(ofd, " [ORIGINAL MESSAGE] %zu octets\n", sizeof(*hdr));
errmsg = nlmsg_inherit(&err->msg);
print_hdr(ofd, errmsg);
diff --git a/lib/nl.c b/lib/nl.c
index b572a1a..6b2f027 100644
--- a/lib/nl.c
+++ b/lib/nl.c
@@ -417,7 +417,7 @@ errout:
int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
unsigned char **buf, struct ucred **creds)
{
- int n;
+ ssize_t n;
int flags = 0;
static int page_size = 0;
struct iovec iov;
diff --git a/lib/object.c b/lib/object.c
index df1c963..055a208 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -285,14 +285,14 @@ void nl_object_dump_buf(struct nl_object *obj, char *buf, size_t len)
int nl_object_identical(struct nl_object *a, struct nl_object *b)
{
struct nl_object_ops *ops = obj_ops(a);
- int req_attrs;
+ uint32_t req_attrs;
/* Both objects must be of same type */
if (ops != obj_ops(b))
return 0;
req_attrs = ops->oo_id_attrs;
- if (req_attrs == ~0)
+ if (req_attrs == 0xFFFFFFFF)
req_attrs = a->ce_mask & b->ce_mask;
/* Both objects must provide all required attributes to uniquely
diff --git a/lib/route/addr.c b/lib/route/addr.c
index deb88ba..600857b 100644
--- a/lib/route/addr.c
+++ b/lib/route/addr.c
@@ -625,7 +625,7 @@ nla_put_failure:
int rtnl_addr_build_add_request(struct rtnl_addr *addr, int flags,
struct nl_msg **result)
{
- int required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY |
+ uint32_t required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY |
ADDR_ATTR_PREFIXLEN | ADDR_ATTR_LOCAL;
if ((addr->ce_mask & required) != required)
@@ -698,7 +698,7 @@ int rtnl_addr_add(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
int rtnl_addr_build_delete_request(struct rtnl_addr *addr, int flags,
struct nl_msg **result)
{
- int required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY;
+ uint32_t required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY;
if ((addr->ce_mask & required) != required)
return -NLE_MISSING_ATTR;
diff --git a/lib/route/class.c b/lib/route/class.c
index 2a9606b..399e8a2 100644
--- a/lib/route/class.c
+++ b/lib/route/class.c
@@ -100,7 +100,7 @@ void rtnl_class_put(struct rtnl_class *class)
static int class_build(struct rtnl_class *class, int type, int flags,
struct nl_msg **result)
{
- int needed = TCA_ATTR_PARENT | TCA_ATTR_HANDLE;
+ uint32_t needed = TCA_ATTR_PARENT | TCA_ATTR_HANDLE;
if ((class->ce_mask & needed) == needed &&
TC_H_MAJ(class->c_parent) && TC_H_MAJ(class->c_handle) &&
@@ -196,7 +196,7 @@ int rtnl_class_build_delete_request(struct rtnl_class *class, struct nl_msg **re
{
struct nl_msg *msg;
struct tcmsg tchdr;
- int required = TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE;
+ uint32_t required = TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE;
if ((class->ce_mask & required) != required) {
APPBUG("ifindex and handle must be specified");
diff --git a/lib/route/classid.c b/lib/route/classid.c
index e1880af..a128773 100644
--- a/lib/route/classid.c
+++ b/lib/route/classid.c
@@ -154,7 +154,8 @@ char *rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
int rtnl_tc_str2handle(const char *str, uint32_t *res)
{
char *colon, *end;
- uint32_t h, err;
+ uint32_t h;
+ int err;
if (!strcasecmp(str, "root")) {
*res = TC_H_ROOT;
diff --git a/lib/route/cls.c b/lib/route/cls.c
index fb2e9be..35a010a 100644
--- a/lib/route/cls.c
+++ b/lib/route/cls.c
@@ -37,7 +37,7 @@ static int cls_build(struct rtnl_cls *cls, int type, int flags,
{
int err, prio, proto;
struct tcmsg *tchdr;
- int required = TCA_ATTR_IFINDEX;
+ uint32_t required = TCA_ATTR_IFINDEX;
if ((cls->ce_mask & required) != required) {
APPBUG("ifindex must be specified");
@@ -251,7 +251,7 @@ int rtnl_cls_change(struct nl_sock *sk, struct rtnl_cls *cls, int flags)
int rtnl_cls_build_delete_request(struct rtnl_cls *cls, int flags,
struct nl_msg **result)
{
- int required = CLS_ATTR_PRIO;
+ uint32_t required = CLS_ATTR_PRIO;
if ((cls->ce_mask & required) != required) {
APPBUG("prio must be specified");
diff --git a/lib/route/cls/u32.c b/lib/route/cls/u32.c
index 331e714..d3e326d 100644
--- a/lib/route/cls/u32.c
+++ b/lib/route/cls/u32.c
@@ -116,7 +116,7 @@ static int u32_msg_parser(struct rtnl_tc *tc, void *data)
if (tb[TCA_U32_PCNT]) {
struct tc_u32_sel *sel;
- int pcnt_size;
+ size_t pcnt_size;
if (!tb[TCA_U32_SEL]) {
err = -NLE_MISSING_ATTR;
diff --git a/lib/route/link/vlan.c b/lib/route/link/vlan.c
index a30ff77..a9bf955 100644
--- a/lib/route/link/vlan.c
+++ b/lib/route/link/vlan.c
@@ -114,7 +114,7 @@ static int vlan_parse(struct rtnl_link *link, struct nlattr *data,
return -NLE_INVAL;
map = nla_data(nla);
- if (map->from < 0 || map->from > VLAN_PRIO_MAX) {
+ if (map->from > VLAN_PRIO_MAX) {
return -NLE_INVAL;
}
@@ -181,7 +181,8 @@ static void vlan_dump_line(struct rtnl_link *link, struct nl_dump_params *p)
static void vlan_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
{
struct vlan_info *vi = link->l_info;
- int i, printed;
+ int printed;
+ uint32_t i;
char buf[64];
rtnl_link_vlan_flags2str(vi->vi_flags, buf, sizeof(buf));
@@ -291,7 +292,7 @@ static int vlan_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
if (vi->vi_mask & VLAN_HAS_EGRESS_QOS) {
struct ifla_vlan_qos_mapping map;
struct nlattr *qos;
- int i;
+ uint32_t i;
if (!(qos = nla_nest_start(msg, IFLA_VLAN_EGRESS_QOS)))
goto nla_put_failure;
diff --git a/lib/route/qdisc.c b/lib/route/qdisc.c
index e5a8aa0..3d618c6 100644
--- a/lib/route/qdisc.c
+++ b/lib/route/qdisc.c
@@ -275,7 +275,7 @@ int rtnl_qdisc_build_delete_request(struct rtnl_qdisc *qdisc,
{
struct nl_msg *msg;
struct tcmsg tchdr;
- int required = TCA_ATTR_IFINDEX | TCA_ATTR_PARENT;
+ uint32_t required = TCA_ATTR_IFINDEX | TCA_ATTR_PARENT;
if ((qdisc->ce_mask & required) != required) {
APPBUG("ifindex and parent must be specified");
diff --git a/lib/route/qdisc/netem.c b/lib/route/qdisc/netem.c
index 3e5ba52..ddd404d 100644
--- a/lib/route/qdisc/netem.c
+++ b/lib/route/qdisc/netem.c
@@ -827,7 +827,8 @@ int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist
BUG();
FILE *f;
- int i, n = 0;
+ int n = 0;
+ size_t i;
size_t len = 2048;
char *line;
char name[NAME_MAX];
diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c
index ac634ae..685a926 100644
--- a/lib/route/route_obj.c
+++ b/lib/route/route_obj.c
@@ -724,7 +724,7 @@ 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;
- int i;
+ uint32_t i;
if (r->ce_mask & ROUTE_ATTR_MULTIPATH && r->rt_nr_nh > n) {
i = 0;
diff --git a/lib/utils.c b/lib/utils.c
index efb2cf4..467fd7f 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -305,7 +305,7 @@ static const struct {
*/
char *nl_size2str(const size_t size, char *buf, const size_t len)
{
- int i;
+ size_t i;
for (i = 0; i < ARRAY_SIZE(size_units); i++) {
if (size >= size_units[i].limit) {
@@ -515,10 +515,12 @@ int nl_str2msec(const char *str, uint64_t *result)
*/
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
{
- int i, split[5];
- char *units[] = {"d", "h", "m", "s", "msec"};
+ uint64_t split[5];
+ size_t i;
+ static const char *units[5] = {"d", "h", "m", "s", "msec"};
+ char * const buf_orig = buf;
-#define _SPLIT(idx, unit) if ((split[idx] = msec / unit) > 0) msec %= unit
+#define _SPLIT(idx, unit) if ((split[idx] = msec / unit)) msec %= unit
_SPLIT(0, 86400000); /* days */
_SPLIT(1, 3600000); /* hours */
_SPLIT(2, 60000); /* minutes */
@@ -526,18 +528,17 @@ char * nl_msec2str(uint64_t msec, char *buf, size_t len)
#undef _SPLIT
split[4] = msec;
- memset(buf, 0, len);
-
- for (i = 0; i < ARRAY_SIZE(split); i++) {
- if (split[i] > 0) {
- char t[64];
- snprintf(t, sizeof(t), "%s%d%s",
- strlen(buf) ? " " : "", split[i], units[i]);
- strncat(buf, t, len - strlen(buf) - 1);
- }
+ for (i = 0; i < ARRAY_SIZE(split) && len; i++) {
+ int l;
+ if (split[i] == 0)
+ continue;
+ l = snprintf(buf, len, "%s%" PRIu64 "%s",
+ (buf==buf_orig) ? "" : " ", split[i], units[i]);
+ buf += l;
+ len -= l;
}
- return buf;
+ return buf_orig;
}
/** @} */
@@ -929,7 +930,7 @@ void __trans_list_clear(struct nl_list_head *head)
char *__type2str(int type, char *buf, size_t len,
const struct trans_tbl *tbl, size_t tbl_len)
{
- int i;
+ size_t i;
for (i = 0; i < tbl_len; i++) {
if (tbl[i].i == type) {
snprintf(buf, len, "%s", tbl[i].a);
@@ -960,7 +961,7 @@ char *__list_type2str(int type, char *buf, size_t len,
char *__flags2str(int flags, char *buf, size_t len,
const struct trans_tbl *tbl, size_t tbl_len)
{
- int i;
+ size_t i;
int tmp = flags;
memset(buf, 0, len);
@@ -981,7 +982,7 @@ int __str2type(const char *buf, const struct trans_tbl *tbl, size_t tbl_len)
{
unsigned long l;
char *end;
- int i;
+ size_t i;
if (*buf == '\0')
return -NLE_INVAL;
@@ -1020,7 +1021,9 @@ int __list_str2type(const char *buf, struct nl_list_head *head)
int __str2flags(const char *buf, const struct trans_tbl *tbl, size_t tbl_len)
{
- int i, flags = 0, len;
+ int flags = 0;
+ size_t i;
+ size_t len; /* ptrdiff_t ? */
char *p = (char *) buf, *t;
for (;;) {
diff --git a/src/lib/route.c b/src/lib/route.c
index 05cb2ad..f2d6c60 100644
--- a/src/lib/route.c
+++ b/src/lib/route.c
@@ -198,12 +198,16 @@ void nl_cli_route_parse_table(struct rtnl_route *route, char *arg)
{
unsigned long lval;
char *endptr;
+ int table;
lval = strtoul(arg, &endptr, 0);
if (endptr == arg) {
- if ((lval = rtnl_route_str2table(arg)) < 0)
+ if ((table = rtnl_route_str2table(arg)) < 0)
nl_cli_fatal(EINVAL, "Unknown table name \"%s\"", arg);
}
+ else {
+ table = lval;
+ }
rtnl_route_set_table(route, lval);
}
@@ -233,16 +237,20 @@ void nl_cli_route_parse_protocol(struct rtnl_route *route, char *arg)
{
unsigned long lval;
char *endptr;
+ int proto;
lval = strtoul(arg, &endptr, 0);
if (endptr == arg) {
- if ((lval = rtnl_route_str2proto(arg)) < 0)
+ if ((proto = rtnl_route_str2proto(arg)) < 0)
nl_cli_fatal(EINVAL,
"Unknown routing protocol name \"%s\"",
arg);
}
+ else {
+ proto = lval;
+ }
- rtnl_route_set_protocol(route, lval);
+ rtnl_route_set_protocol(route, proto);
}
void nl_cli_route_parse_type(struct rtnl_route *route, char *arg)