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.
This commit is contained in:
parent
4f93364862
commit
2bdcde7e8e
18 changed files with 63 additions and 51 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
2
lib/nl.c
2
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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
39
lib/utils.c
39
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 (;;) {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue