From bca202668f3e699a25fe015ece81b063bb40a5ad Mon Sep 17 00:00:00 2001 From: Samir Hussain Date: Tue, 23 Oct 2018 16:03:42 -0400 Subject: [PATCH] Applying patch that reduces compile warnings and fixes warnings from gcc and clang. Patch contributed by: Gareth (gareth@oneroi.org.uk) --- Makefile | 2 +- avp.c | 3 +++ call.c | 2 ++ control.c | 21 +++++++++++---------- file.c | 6 +++++- l2tp.h | 1 + misc.c | 6 +++++- misc.h | 4 ++-- network.c | 1 + xl2tpd-control.c | 30 +++++++++++++++++++++--------- xl2tpd.c | 17 +++++++++++++---- 11 files changed, 65 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 0efb5459..9927715c 100644 --- a/Makefile +++ b/Makefile @@ -100,7 +100,7 @@ OSFLAGS+= -DUSE_KERNEL IPFLAGS?= -DIP_ALLOCATION -CFLAGS+= $(DFLAGS) -Os -Wall -DSANITY $(OSFLAGS) $(IPFLAGS) +CFLAGS+= $(DFLAGS) -Os -Wall -Wextra -DSANITY $(OSFLAGS) $(IPFLAGS) HDRS=l2tp.h avp.h misc.h control.h call.h scheduler.h file.h aaa.h md5.h OBJS=xl2tpd.o pty.o misc.o control.o avp.o call.o network.o avpsend.o scheduler.o file.o aaa.o md5.o SRCS=${OBJS:.o=.c} ${HDRS} diff --git a/avp.c b/avp.c index 4c5f7994..d12d496c 100644 --- a/avp.c +++ b/avp.c @@ -388,6 +388,8 @@ int ignore_avp (struct tunnel *t, struct call *c, void *data, int datalen) * One option is to simply change the options we pass to pppd. * */ + UNUSED(data); + UNUSED(datalen); if (gconfig.debug_avp) { if (DEBUG) @@ -398,6 +400,7 @@ int ignore_avp (struct tunnel *t, struct call *c, void *data, int datalen) int seq_reqd_avp (struct tunnel *t, struct call *c, void *data, int datalen) { + UNUSED(data); #ifdef SANITY if (t->sanity) { diff --git a/call.c b/call.c index f7482592..dc43f56a 100644 --- a/call.c +++ b/call.c @@ -577,6 +577,8 @@ struct call *new_call (struct tunnel *parent) struct call *get_tunnel (int tunnel, unsigned int addr, int port) { + UNUSED(addr); + UNUSED(port); struct tunnel *st; if (tunnel) { diff --git a/control.c b/control.c index 3b0711e5..f0399cf3 100644 --- a/control.c +++ b/control.c @@ -90,7 +90,7 @@ void add_fcs (struct buffer *buf) { _u16 fcs = PPP_INITFCS; unsigned char *c = buf->start; - int x; + size_t x; for (x = 0; x < buf->len; x++) { fcs = PPP_FCS (fcs, *c); @@ -1314,7 +1314,7 @@ static inline int check_payload (struct buffer *buf, struct tunnel *t, * or not. Returns 0 on success. */ - int ehlen = MIN_PAYLOAD_HDR_LEN; + size_t ehlen = MIN_PAYLOAD_HDR_LEN; struct payload_hdr *h = (struct payload_hdr *) (buf->start); if (!c) { @@ -1415,6 +1415,7 @@ static inline int check_payload (struct buffer *buf, struct tunnel *t, static inline int expand_payload (struct buffer *buf, struct tunnel *t, struct call *c) { + UNUSED(t); /* * Expands payload header. Does not check for valid header, * check_payload() should already be called as a prerequisite. @@ -1599,7 +1600,7 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal * Write a packet, doing sync->async conversion if * necessary */ - int x; + size_t x; unsigned char e; int err; static unsigned char wbuf[MAX_RECV_SIZE]; @@ -1629,17 +1630,17 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal /* We are given async frames, so write them directly to the tty */ err = write (c->fd, buf->start, buf->len); - if (err == buf->len) + if ((size_t)err == buf->len) { return 0; } - else if (err == 0) + else if ((size_t)err == 0) { l2tp_log (LOG_WARNING, "%s: wrote no bytes of async packet\n", __FUNCTION__); return -EINVAL; } - else if (err < 0) + else if ((size_t)err < 0) { if ((errno == EAGAIN) || (errno == EINTR)) { @@ -1651,13 +1652,13 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal strerror (errno)); } } - else if (err < buf->len) + else if ((size_t)err < buf->len) { l2tp_log (LOG_WARNING, "%s: short write (%d of %d bytes)\n", __FUNCTION__, err, buf->len); return -EINVAL; } - else if (err > buf->len) + else if ((size_t)err > buf->len) { l2tp_log (LOG_WARNING, "%s: write returned LONGER than buffer length?\n", __FUNCTION__); @@ -1678,7 +1679,7 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal { // we must at least still have 3 bytes left in the worst case scenario: // 1 for a possible escape, 1 for the value and 1 to end the PPP stream. - if(pos >= (sizeof(wbuf) - 4)) { + if((size_t)pos >= (sizeof(wbuf) - 4)) { if(DEBUG) l2tp_log(LOG_CRIT, "%s: rx packet is too big after PPP encoding (size %u, max is %u)\n", __FUNCTION__, buf->len, MAX_RECV_SIZE); @@ -1704,7 +1705,7 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal #endif x = 0; - while ( pos != x ) + while ((size_t) pos != x ) { err = write (c->fd, wbuf+x, pos-x); if ( err < 0 ) { diff --git a/file.c b/file.c index a6362c06..f4cfefb0 100644 --- a/file.c +++ b/file.c @@ -217,6 +217,7 @@ int set_int (char *word, char *value, int *ptr) int set_string (char *word, char *value, char *ptr, int len) { + UNUSED(word); #ifdef DEBUG_FILE l2tp_log (LOG_DEBUG, "set_%s: %s flag to '%s'\n", word, word, value); #endif /* ; */ @@ -930,7 +931,7 @@ struct iprange *set_range (char *word, char *value, struct iprange *in) } } /* Copy the last field + null terminator */ - if (ip_hi + sizeof(ip_hi)-e > strlen(d)) { + if ((size_t)(ip_hi + sizeof(ip_hi)-e) > strlen(d)) { strcpy(e, d); d = ip_hi; } @@ -1058,6 +1059,7 @@ int set_exclusive (char *word, char *value, int context, void *item) int set_ip (char *word, char *value, unsigned int *addr) { + UNUSED(word); struct hostent *hp; hp = gethostbyname (value); if (!hp) @@ -1244,6 +1246,7 @@ int set_rand_dev () int set_rand_egd (char *value) { + UNUSED(value); l2tp_log(LOG_WARNING, "%s: not yet implemented!\n", __FUNCTION__); rand_source = RAND_EGD; return -1; @@ -1251,6 +1254,7 @@ int set_rand_egd (char *value) int set_rand_source (char *word, char *value, int context, void *item) { + UNUSED(item); time_t seconds; /* * We're going to go ahead and seed the rand() function with srand() diff --git a/l2tp.h b/l2tp.h index 200e290d..dbe23926 100644 --- a/l2tp.h +++ b/l2tp.h @@ -41,6 +41,7 @@ typedef unsigned long long _u64; #define CONTROL_PIPE "/var/run/xl2tpd/l2tp-control" #define CONTROL_PIPE_MESSAGE_SIZE 1024 +#define UNUSED(x) (void)(x) /* Control pip request types */ #define CONTROL_PIPE_REQ_LAC_REMOVE 'r' diff --git a/misc.c b/misc.c index e11881f1..322af264 100644 --- a/misc.c +++ b/misc.c @@ -39,6 +39,8 @@ static int syslog_nesting = 0; --syslog_nesting; \ } while(0) +#define UNUSED(x) (void)(x) + void init_log() { static int logopen=0; @@ -150,7 +152,7 @@ void bufferDump (unsigned char *buf, int buflen) void do_packet_dump (struct buffer *buf) { - int x; + size_t x; unsigned char *c = buf->start; printf ("packet dump: \nHEX: { "); for (x = 0; x < buf->len; x++) @@ -260,6 +262,8 @@ void opt_destroy (struct ppp_opts *option) int get_egd_entropy(char *buf, int count) { + UNUSED(buf); + UNUSED(count); return -1; } diff --git a/misc.h b/misc.h index caab7a14..960a4740 100644 --- a/misc.h +++ b/misc.h @@ -24,8 +24,8 @@ struct buffer void *rstart; void *rend; void *start; - int len; - int maxlen; + size_t len; + size_t maxlen; #if 0 unsigned int addr; int port; diff --git a/network.c b/network.c index 6f2a2134..cb0121a4 100644 --- a/network.c +++ b/network.c @@ -183,6 +183,7 @@ static inline void fix_hdr (void *buf) void dethrottle (void *call) { + UNUSED(call); /* struct call *c = (struct call *)call; */ /* if (c->throttle) { #ifdef DEBUG_FLOW diff --git a/xl2tpd-control.c b/xl2tpd-control.c index c2345ce9..e81c616e 100644 --- a/xl2tpd-control.c +++ b/xl2tpd-control.c @@ -87,22 +87,22 @@ struct command_t commands[] = { }, /* LAC commands */ - {"add-lac", &command_add_lac, TUNNEL_REQUIRED}, - {"connect-lac", &command_connect_lac, TUNNEL_REQUIRED}, - {"disconnect-lac", &command_disconnect_lac, TUNNEL_REQUIRED}, - {"remove-lac", &command_remove_lac, TUNNEL_REQUIRED}, + {"add-lac", &command_add_lac, TUNNEL_REQUIRED, ""}, + {"connect-lac", &command_connect_lac, TUNNEL_REQUIRED, ""}, + {"disconnect-lac", &command_disconnect_lac, TUNNEL_REQUIRED, ""}, + {"remove-lac", &command_remove_lac, TUNNEL_REQUIRED, ""}, /* LNS commands */ {"add-lns", &command_add_lns, TUNNEL_REQUIRED, "\tadd-lns\tadds new or modify existing lns configuration.\n" }, - {"remove-lns", &command_remove_lns, TUNNEL_REQUIRED}, + {"remove-lns", &command_remove_lns, TUNNEL_REQUIRED, ""}, /* Generic commands */ - {"status", &command_status_lac, TUNNEL_REQUIRED}, - {"status-lns", &command_status_lns, TUNNEL_REQUIRED}, - {"available", &command_available, TUNNEL_NOT_REQUIRED}, - {NULL, NULL} + {"status", &command_status_lac, TUNNEL_REQUIRED, ""}, + {"status-lns", &command_status_lns, TUNNEL_REQUIRED, ""}, + {"available", &command_available, TUNNEL_NOT_REQUIRED, ""}, + {NULL, NULL, 0, NULL} }; void usage() @@ -463,6 +463,8 @@ int command_connect_lac int command_disconnect_lac (FILE* mesf, char* tunnel, int optc, char *optv[]) { + UNUSED(optc); + UNUSED(optv); fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LAC_DISCONNECT, tunnel); return 0; } @@ -470,6 +472,8 @@ int command_disconnect_lac int command_remove_lac (FILE* mesf, char* tunnel, int optc, char *optv[]) { + UNUSED(optc); + UNUSED(optv); fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LAC_REMOVE, tunnel); return 0; } @@ -477,6 +481,8 @@ int command_remove_lac int command_status_lns (FILE* mesf, char* tunnel, int optc, char *optv[]) { + UNUSED(optc); + UNUSED(optv); fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LNS_STATUS, tunnel); return 0; } @@ -484,6 +490,8 @@ int command_status_lns int command_status_lac (FILE* mesf, char* tunnel, int optc, char *optv[]) { + UNUSED(optc); + UNUSED(optv); fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LAC_STATUS, tunnel); return 0; } @@ -491,6 +499,8 @@ int command_status_lac int command_available (FILE* mesf, char* tunnel, int optc, char *optv[]) { + UNUSED(optc); + UNUSED(optv); fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_AVAILABLE, tunnel); return 0; } @@ -498,6 +508,8 @@ int command_available int command_remove_lns (FILE* mesf, char* tunnel, int optc, char *optv[]) { + UNUSED(optc); + UNUSED(optv); fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LNS_REMOVE, tunnel); return 0; } diff --git a/xl2tpd.c b/xl2tpd.c index c1b8b70e..9a3534e4 100644 --- a/xl2tpd.c +++ b/xl2tpd.c @@ -75,7 +75,7 @@ int control_handle_lac_hangup(FILE* resf, char* bufp); int control_handle_lac_disconnect(FILE* resf, char* bufp); int control_handle_lac_add_modify(FILE* resf, char* bufp); int control_handle_lac_remove(FILE* resf, char* bufp); -int control_handle_lac_status(FILE* resf, char* bufp); +int control_handle_lac_status(); int control_handle_lns_remove(FILE* resf, char* bufp); struct control_requests_handler control_handlers[] = { @@ -210,6 +210,7 @@ void show_status (void) void null_handler(int sig) { + UNUSED(sig); /* FIXME * A sighup is received when a call is terminated, unknown origine .. * I catch it and ll looks good, but .. @@ -218,11 +219,13 @@ void null_handler(int sig) void status_handler (int sig) { + UNUSED(sig); show_status (); } -void child_handler (int signal) +void child_handler (int sig) { + UNUSED(sig); /* * Oops, somebody we launched was killed. * It's time to reap them and close that call. @@ -340,26 +343,31 @@ void death_handler (int signal) void sigterm_handler(int sig) { + UNUSED(sig); sigterm_received = 1; } void sigint_handler(int sig) { + UNUSED(sig); sigint_received = 1; } void sigchld_handler(int sig) { + UNUSED(sig); sigchld_received = 1; } void sigusr1_handler(int sig) { + UNUSED(sig); sigusr1_received = 1; } void sighup_handler(int sig) { + UNUSED(sig); sighup_received = 1; } @@ -1020,7 +1028,8 @@ struct lns* find_lns_by_name(char* name){ return NULL; /* ml: Ok we could not find anything*/ } -int control_handle_available(FILE* resf, char* bufp){ +int control_handle_available(FILE* resf, char* bufp) { + UNUSED(bufp); struct lac *lac; struct lns *lns; @@ -1529,7 +1538,7 @@ int control_handle_lac_remove(FILE* resf, char* bufp){ return 1; } -int control_handle_lac_status(FILE* resf, char* bufp){ +int control_handle_lac_status(){ show_status (); return 1; }