From 45bc175ef9278c175d2fc3a0678b49b18e74c449 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 14 Feb 2018 14:50:04 -0800 Subject: fixes #234 Investigate enabling more verbose compiler warnings We enabled verbose compiler warnings, and found a lot of issues. Some of these were even real bugs. As a bonus, we actually save some initialization steps in the compat layer, and avoid passing some variables we don't need. --- src/core/aio.c | 26 +++++++++++++------------- src/core/aio.h | 14 +++++++------- src/core/defs.h | 2 +- src/core/endpt.c | 1 + src/core/url.c | 12 ++++++------ 5 files changed, 28 insertions(+), 27 deletions(-) (limited to 'src/core') diff --git a/src/core/aio.c b/src/core/aio.c index 1c293020..dd5edf0e 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -215,51 +215,51 @@ nni_aio_get_msg(nni_aio *aio) } void -nni_aio_set_data(nni_aio *aio, int index, void *data) +nni_aio_set_data(nni_aio *aio, unsigned index, void *data) { - if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_user_data))) { + if (index < NNI_NUM_ELEMENTS(aio->a_user_data)) { aio->a_user_data[index] = data; } } void * -nni_aio_get_data(nni_aio *aio, int index) +nni_aio_get_data(nni_aio *aio, unsigned index) { - if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_user_data))) { + if (index < NNI_NUM_ELEMENTS(aio->a_user_data)) { return (aio->a_user_data[index]); } return (NULL); } void -nni_aio_set_input(nni_aio *aio, int index, void *data) +nni_aio_set_input(nni_aio *aio, unsigned index, void *data) { - if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_inputs))) { + if (index < NNI_NUM_ELEMENTS(aio->a_inputs)) { aio->a_inputs[index] = data; } } void * -nni_aio_get_input(nni_aio *aio, int index) +nni_aio_get_input(nni_aio *aio, unsigned index) { - if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_inputs))) { + if (index < NNI_NUM_ELEMENTS(aio->a_inputs)) { return (aio->a_inputs[index]); } return (NULL); } void -nni_aio_set_output(nni_aio *aio, int index, void *data) +nni_aio_set_output(nni_aio *aio, unsigned index, void *data) { - if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_outputs))) { + if (index < NNI_NUM_ELEMENTS(aio->a_outputs)) { aio->a_outputs[index] = data; } } void * -nni_aio_get_output(nni_aio *aio, int index) +nni_aio_get_output(nni_aio *aio, unsigned index) { - if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_outputs))) { + if (index < NNI_NUM_ELEMENTS(aio->a_outputs)) { return (aio->a_outputs[index]); } return (NULL); @@ -315,7 +315,7 @@ nni_aio_start(nni_aio *aio, nni_aio_cancelfn cancelfn, void *data) aio->a_prov_cancel = cancelfn; aio->a_prov_data = data; aio->a_active = 1; - for (int i = 0; i < NNI_NUM_ELEMENTS(aio->a_outputs); i++) { + for (unsigned i = 0; i < NNI_NUM_ELEMENTS(aio->a_outputs); i++) { aio->a_outputs[i] = NULL; } diff --git a/src/core/aio.h b/src/core/aio.h index 718eeb91..141248b8 100644 --- a/src/core/aio.h +++ b/src/core/aio.h @@ -52,28 +52,28 @@ extern void nni_aio_stop(nni_aio *); // consumer, initiating the I/O. The intention is to be able to store // additional data for use when the operation callback is executed. // The index represents the "index" at which to store the data. A maximum -// of 4 elements can be stored with the (index >= 0 && index < 4). -extern void nni_aio_set_data(nni_aio *, int, void *); +// of 4 elements can be stored with the (index < 4). +extern void nni_aio_set_data(nni_aio *, unsigned, void *); // nni_aio_get_data returns the user data that was previously stored // with nni_aio_set_data. -extern void *nni_aio_get_data(nni_aio *, int); +extern void *nni_aio_get_data(nni_aio *, unsigned); // nni_set_input sets input parameters on the AIO. The semantic details // of this will be determined by the specific AIO operation. AIOs can // carry up to 4 input parameters. -extern void nni_aio_set_input(nni_aio *, int, void *); +extern void nni_aio_set_input(nni_aio *, unsigned, void *); // nni_get_input returns the input value stored by nni_aio_set_input. -extern void *nni_aio_get_input(nni_aio *, int); +extern void *nni_aio_get_input(nni_aio *, unsigned); // nni_set_output sets output results on the AIO, allowing providers to // return results to consumers. The semantic details are determined by // the AIO operation. Up to 4 outputs can be carried on an AIO. -extern void nni_aio_set_output(nni_aio *, int, void *); +extern void nni_aio_set_output(nni_aio *, unsigned, void *); // nni_get_output returns an output previously stored on the AIO. -extern void *nni_aio_get_output(nni_aio *, int); +extern void *nni_aio_get_output(nni_aio *, unsigned); // XXX: These should be refactored in terms of generic inputs and outputs. extern void nni_aio_set_msg(nni_aio *, nni_msg *); diff --git a/src/core/defs.h b/src/core/defs.h index dbbccf58..b08ce838 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -27,7 +27,7 @@ #endif // Returns the size of an array in elements. (Convenience.) -#define NNI_NUM_ELEMENTS(x) (sizeof(x) / sizeof((x)[0])) +#define NNI_NUM_ELEMENTS(x) ((unsigned) (sizeof(x) / sizeof((x)[0]))) // These types are common but have names shared with user space. // Internal code should use these names when possible. diff --git a/src/core/endpt.c b/src/core/endpt.c index b7167ad7..4d3727bc 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -510,6 +510,7 @@ int nni_ep_listen(nni_ep *ep, int flags) { int rv = 0; + NNI_ARG_UNUSED(flags); nni_sock_reconntimes(ep->ep_sock, &ep->ep_inirtime, &ep->ep_maxrtime); ep->ep_currtime = ep->ep_inirtime; diff --git a/src/core/url.c b/src/core/url.c index 2cdb43c2..93f1298e 100644 --- a/src/core/url.c +++ b/src/core/url.c @@ -127,8 +127,8 @@ url_canonify_uri(char **outp, const char *in) out[dst++] = (char) c; } else { out[dst++] = '%'; - out[dst++] = toupper(out[src + 1]); - out[dst++] = toupper(out[src + 2]); + out[dst++] = (char) toupper(out[src + 1]); + out[dst++] = (char) toupper(out[src + 2]); } src += 3; continue; @@ -152,7 +152,7 @@ url_canonify_uri(char **outp, const char *in) if ((c == '?') || (c == '#')) { skip = true; } - out[dst++] = c; + out[dst++] = (char) c; src++; } out[dst] = 0; @@ -186,7 +186,7 @@ url_canonify_uri(char **outp, const char *in) if ((c == '?') || (c == '#')) { skip = true; } - out[dst++] = c; + out[dst++] = (char) c; src++; } } @@ -285,7 +285,7 @@ nni_url_parse(nni_url **urlp, const char *raw) goto error; } for (size_t i = 0; i < len; i++) { - url->u_scheme[i] = tolower(s[i]); + url->u_scheme[i] = (char) tolower(s[i]); } url->u_scheme[len] = '\0'; @@ -335,7 +335,7 @@ nni_url_parse(nni_url **urlp, const char *raw) // Copy the host portion, but make it lower case (hostnames are // case insensitive). for (size_t i = 0; i < len; i++) { - url->u_host[i] = tolower(s[i]); + url->u_host[i] = (char) tolower(s[i]); } url->u_host[len] = '\0'; s += len; -- cgit v1.2.3-70-g09d2