From 48af0110f88d63bc351579974ceafde352ebe8e2 Mon Sep 17 00:00:00 2001 From: Peter Millerchip Date: Thu, 20 Aug 2015 14:38:44 +0100 Subject: Compile with -W -Wall -Werror --- src/lib/Makefile.in | 2 +- src/lib/libnetlink.c | 16 ++++++++-------- src/lib/pid.c | 20 +++++++++++++------- 3 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in index 6e6be1910..3d9d1d7e2 100644 --- a/src/lib/Makefile.in +++ b/src/lib/Makefile.in @@ -6,7 +6,7 @@ H_FILE_LIST = $(wildcard *.[h]) C_FILE_LIST = $(wildcard *.c) OBJS = $(C_FILE_LIST:.c=.o) BINOBJS = $(foreach file, $(OBJS), $file) -CFLAGS += -ggdb -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security +CFLAGS += -ggdb -W -Wall -Werror -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security LDFLAGS:=-pic -Wl,-z,relro -Wl,-z,now all: $(OBJS) diff --git a/src/lib/libnetlink.c b/src/lib/libnetlink.c index 264632a01..40fb099f7 100644 --- a/src/lib/libnetlink.c +++ b/src/lib/libnetlink.c @@ -363,7 +363,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, fprintf(stderr, "sender address length == %d\n", msg.msg_namelen); exit(1); } - for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { + for (h = (struct nlmsghdr*)buf; status >= (int)sizeof(*h); ) { int len = h->nlmsg_len; int l = len - sizeof(*h); @@ -376,7 +376,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, exit(1); } - if (nladdr.nl_pid != peer || + if ((pid_t)(nladdr.nl_pid) != peer || h->nlmsg_pid != rtnl->local.nl_pid || h->nlmsg_seq != seq) { /* Don't forget to skip that message. */ @@ -387,7 +387,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); - if (l < sizeof(struct nlmsgerr)) { + if (l < (int)sizeof(struct nlmsgerr)) { fprintf(stderr, "ERROR truncated\n"); } else { if (!err->error) { @@ -465,7 +465,7 @@ int rtnl_listen(struct rtnl_handle *rtnl, fprintf(stderr, "Sender address length == %d\n", msg.msg_namelen); exit(1); } - for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { + for (h = (struct nlmsghdr*)buf; status >= (int)sizeof(*h); ) { int err; int len = h->nlmsg_len; int l = len - sizeof(*h); @@ -528,7 +528,7 @@ int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler, len = h->nlmsg_len; l = len - sizeof(*h); - if (l<0 || len>sizeof(buf)) { + if (l < 0 || len > (int)sizeof(buf)) { fprintf(stderr, "!!!malformed message: len=%d @%lu\n", len, ftell(rtnl)); return -1; @@ -619,7 +619,7 @@ printf("\tdata length: %d\n", alen); int len = RTA_LENGTH(alen); struct rtattr *rta; - if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) { + if ((int)(NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len)) > maxlen) { fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen); return -1; } @@ -673,7 +673,7 @@ else int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len) { - if (NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len) > maxlen) { + if ((int)(NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len)) > maxlen) { fprintf(stderr, "addraw_l ERROR: message exceeded bound of %d\n",maxlen); return -1; } @@ -792,7 +792,7 @@ int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int l int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len) { - if (RTA_PAYLOAD(rta) < len) + if ((int)RTA_PAYLOAD(rta) < len) return -1; if (RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr)) { rta = RTA_DATA(rta) + RTA_ALIGN(len); diff --git a/src/lib/pid.c b/src/lib/pid.c index a0261ead2..1a1797ce2 100644 --- a/src/lib/pid.c +++ b/src/lib/pid.c @@ -222,15 +222,18 @@ static void print_elem(unsigned index, int nowrap) { // recursivity!!! void pid_print_tree(unsigned index, unsigned parent, int nowrap) { print_elem(index, nowrap); + + // Remove unused parameter warning + (void)parent; - int i; - for (i = index + 1; i < max_pids; i++) { - if (pids[i].parent == index) + unsigned i; + for (i = index + 1; i < (unsigned)max_pids; i++) { + if (pids[i].parent == (pid_t)index) pid_print_tree(i, index, nowrap); } for (i = 0; i < index; i++) { - if (pids[i].parent == index) + if (pids[i].parent == (pid_t)index) pid_print_tree(i, index, nowrap); } } @@ -245,6 +248,9 @@ void pid_store_cpu(unsigned index, unsigned parent, unsigned *utime, unsigned *s *utime = 0; *stime = 0; } + + // Remove unused parameter warning + (void)parent; unsigned utmp = 0; unsigned stmp = 0; @@ -252,9 +258,9 @@ void pid_store_cpu(unsigned index, unsigned parent, unsigned *utime, unsigned *s *utime += utmp; *stime += stmp; - int i; - for (i = index + 1; i < max_pids; i++) { - if (pids[i].parent == index) + unsigned i; + for (i = index + 1; i < (unsigned)max_pids; i++) { + if (pids[i].parent == (pid_t)index) pid_store_cpu(i, index, utime, stime); } -- cgit v1.2.3-70-g09d2