From dc0e52cb3e42620c3139e713b373d130aa30b698 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 1 May 2018 15:24:35 +0200 Subject: [PATCH] Fix all compiler warnings found using -Wall -W -pedantic. Using both GCC 8 and Clang 7. --- configure.ac | 3 ++- examples/channels.c | 16 +++++++++++++--- examples/chat.c | 14 +++++++++++--- examples/manynodes.c | 21 ++++++++++++--------- examples/meshlinkapp.c | 2 ++ src/chacha-poly1305/chacha-poly1305.c | 6 +++--- src/conf.c | 11 +++++++++-- src/crypto.c | 6 ++++-- src/ed25519/sc.h | 2 +- src/meshlink++.h | 11 ++++++----- src/meshlink.c | 17 +++++++++++++---- src/net_packet.c | 4 ++-- src/net_setup.c | 16 +++++++--------- src/netutl.c | 20 ++++++++++++-------- src/prf.c | 2 +- src/protocol.c | 4 +--- src/splay_tree.c | 2 +- src/sptps.c | 12 +++++++----- src/utcp | 2 +- test/basic.c | 2 +- test/basicpp.cpp | 2 +- test/channels-cornercases.c | 22 +++++++++++++++++++--- test/channels-fork.c | 16 +++++++++++++++- test/channels.c | 15 ++++++++++++++- test/echo-fork.c | 20 +++++++++++++++++++- test/import-export.c | 4 +++- test/invite-join.c | 4 +++- test/sign-verify.c | 2 +- test/trio.c | 7 ++++++- test/utils.c | 10 ++++++---- test/utils.h | 2 +- 31 files changed, 197 insertions(+), 80 deletions(-) diff --git a/configure.ac b/configure.ac index b4672e0c..8ef1e9ff 100644 --- a/configure.ac +++ b/configure.ac @@ -58,7 +58,8 @@ dnl No -fstack-protector-all because it doesn't work on all platforms or archite AC_ARG_ENABLE([hardening], AS_HELP_STRING([--disable-hardening], [disable compiler and linker hardening flags])) AS_IF([test "x$enable_hardening" != "xno"], - [AX_CHECK_COMPILE_FLAG([-DFORTIFY_SOURCE=2], [CPPFLAGS="$CPPFLAGS -DFORITFY_SOURCE=2"]) + [CPPFLAGS="$CPPFLAGS -W -pedantic" + AX_CHECK_COMPILE_FLAG([-DFORTIFY_SOURCE=2], [CPPFLAGS="$CPPFLAGS -DFORITFY_SOURCE=2"]) AX_CHECK_COMPILE_FLAG([-fwrapv], [CPPFLAGS="$CPPFLAGS -fwrapv"], [AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CPPFLAGS="$CPPFLAGS -fno-strict-overflow"])] ) diff --git a/examples/channels.c b/examples/channels.c index e56d9d16..2059b387 100644 --- a/examples/channels.c +++ b/examples/channels.c @@ -7,7 +7,9 @@ #define CHAT_PORT 531 static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - const char *levelstr[] = { + (void) mesh; + + static const char *levelstr[] = { [MESHLINK_DEBUG] = "\x1b[34mDEBUG", [MESHLINK_INFO] = "\x1b[32mINFO", [MESHLINK_WARNING] = "\x1b[33mWARNING", @@ -38,6 +40,9 @@ static void channel_receive(meshlink_handle_t *mesh, meshlink_channel_t *channel } static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { + (void)data; + (void)len; + // Only accept connections to the chat port if(port != CHAT_PORT) { fprintf(stderr, "Rejected incoming channel from '%s' to port %u\n", channel->node->name, port); @@ -57,11 +62,15 @@ static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, } static void channel_poll(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { + (void)len; + fprintf(stderr, "Channel to '%s' connected\n", channel->node->name); meshlink_set_channel_poll_cb(mesh, channel, NULL); } static void node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + (void)mesh; + if(reachable) { printf("%s joined.\n", node->name); } else { @@ -139,7 +148,7 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { } else { printf("%zu known nodes:", nnodes); - for(int i = 0; i < nnodes; i++) { + for(size_t i = 0; i < nnodes; i++) { printf(" %s", nodes[i]->name); } @@ -201,7 +210,8 @@ static void parse_input(meshlink_handle_t *mesh, char *buf) { // Commands start with '/' if(*buf == '/') { - return parse_command(mesh, buf + 1); + parse_command(mesh, buf + 1); + return; } // Lines in the form "name: message..." set the destination node. diff --git a/examples/chat.c b/examples/chat.c index 7cf5a480..c26a642d 100644 --- a/examples/chat.c +++ b/examples/chat.c @@ -5,17 +5,22 @@ #include "../src/meshlink.h" static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - const char *levelstr[] = { + (void)mesh; + + static const char *levelstr[] = { [MESHLINK_DEBUG] = "\x1b[34mDEBUG", [MESHLINK_INFO] = "\x1b[32mINFO", [MESHLINK_WARNING] = "\x1b[33mWARNING", [MESHLINK_ERROR] = "\x1b[31mERROR", [MESHLINK_CRITICAL] = "\x1b[31mCRITICAL", }; + fprintf(stderr, "%s:\x1b[0m %s\n", levelstr[level], text); } static void receive(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len) { + (void)mesh; + const char *msg = data; if(!len || msg[len - 1]) { @@ -27,6 +32,8 @@ static void receive(meshlink_handle_t *mesh, meshlink_node_t *source, const void } static void node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + (void)mesh; + if(reachable) { printf("%s joined.\n", node->name); } else { @@ -104,7 +111,7 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { } else { printf("%zu known nodes:", nnodes); - for(int i = 0; i < nnodes; i++) { + for(size_t i = 0; i < nnodes; i++) { printf(" %s", nodes[i]->name); } @@ -166,7 +173,8 @@ static void parse_input(meshlink_handle_t *mesh, char *buf) { // Commands start with '/' if(*buf == '/') { - return parse_command(mesh, buf + 1); + parse_command(mesh, buf + 1); + return; } // Lines in the form "name: message..." set the destination node. diff --git a/examples/manynodes.c b/examples/manynodes.c index 2cfe8180..9e4a95c0 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -53,7 +53,7 @@ static void testmesh() { } else { printf("%zu known nodes:\n", nnodes); - for(int i = 0; i < nnodes; i++) { + for(size_t i = 0; i < nnodes; i++) { //printf(" %s\n", nodes[i]->name); if(!meshlink_send(mesh[nindex], nodes[i], "magic", strlen("magic") + 1)) { fprintf(stderr, "Could not send message to '%s': %s\n", nodes[i]->name, meshlink_strerror(meshlink_errno)); @@ -115,6 +115,8 @@ static bool exportmeshgraph(const char *path) { void exportmeshgraph_timer(int signum) { + (void)signum; + struct timeval ts; gettimeofday(&ts, NULL); @@ -127,12 +129,12 @@ void exportmeshgraph_timer(int signum) { #ifndef _WIN32 static bool exportmeshgraph_started = false; -static bool exportmeshgraph_end(const char *none) { +static bool exportmeshgraph_end(void) { if(!exportmeshgraph_started) { return false; } - struct itimerval zero_timer = { 0 }; + struct itimerval zero_timer; setitimer(ITIMER_REAL, &zero_timer, NULL); @@ -147,7 +149,7 @@ static bool exportmeshgraph_begin(const char *timeout_str) { } if(exportmeshgraph_started) { - if(!exportmeshgraph_end(NULL)) { + if(!exportmeshgraph_end()) { return false; } } @@ -182,7 +184,7 @@ static bool exportmeshgraph_begin(const char *timeout_str) { return true; } #else -static bool exportmeshgraph_end(const char *none) { +static bool exportmeshgraph_end(void) { return false; } @@ -258,7 +260,7 @@ static void parse_command(char *buf) { } else { printf("%zu known nodes:", nnodes); - for(int i = 0; i < nnodes; i++) { + for(size_t i = 0; i < nnodes; i++) { printf(" %s", nodes[i]->name); } @@ -280,7 +282,7 @@ static void parse_command(char *buf) { } else if(!strcasecmp(buf, "egb")) { exportmeshgraph_begin(arg); } else if(!strcasecmp(buf, "ege")) { - exportmeshgraph_end(NULL); + exportmeshgraph_end(); } else if(!strcasecmp(buf, "test")) { testmesh(); } else if(!strcasecmp(buf, "select")) { @@ -345,7 +347,8 @@ static void parse_input(char *buf) { // Commands start with '/' if(*buf == '/') { - return parse_command(buf + 1); + parse_command(buf + 1); + return; } // Lines in the form "name: message..." set the destination node. @@ -465,7 +468,7 @@ int main(int argc, char *argv[]) { parse_input(buf); } - exportmeshgraph_end(NULL); + exportmeshgraph_end(); printf("Nodes stopping.\n"); diff --git a/examples/meshlinkapp.c b/examples/meshlinkapp.c index 9796cba3..2c12ea11 100644 --- a/examples/meshlinkapp.c +++ b/examples/meshlinkapp.c @@ -3,6 +3,8 @@ #include "../src/meshlink.h" void handle_recv_data(meshlink_handle_t *mesh, meshlink_node_t *source, void *data, size_t len) { + (void)mesh; + printf("Received %zu bytes from %s: %s\n", len, source->name, (char *)data); } diff --git a/src/chacha-poly1305/chacha-poly1305.c b/src/chacha-poly1305/chacha-poly1305.c index c7464203..5810dbb5 100644 --- a/src/chacha-poly1305/chacha-poly1305.c +++ b/src/chacha-poly1305/chacha-poly1305.c @@ -24,7 +24,7 @@ void chacha_poly1305_exit(chacha_poly1305_ctx_t *ctx) bool chacha_poly1305_set_key(chacha_poly1305_ctx_t *ctx, const void *key) { chacha_keysetup(&ctx->main_ctx, key, 256); - chacha_keysetup(&ctx->header_ctx, key + 32, 256); + chacha_keysetup(&ctx->header_ctx, (uint8_t *)key + 32, 256); return true; } @@ -60,7 +60,7 @@ bool chacha_poly1305_encrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const v chacha_ivsetup(&ctx->main_ctx, seqbuf, one); chacha_encrypt_bytes(&ctx->main_ctx, indata, outdata, inlen); - poly1305_auth(outdata + inlen, outdata, inlen, poly_key); + poly1305_auth((uint8_t *)outdata + inlen, outdata, inlen, poly_key); if (outlen) *outlen = inlen + POLY1305_TAGLEN; @@ -87,7 +87,7 @@ bool chacha_poly1305_decrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const v /* Check tag before anything else */ inlen -= POLY1305_TAGLEN; - const uint8_t *tag = indata + inlen; + const uint8_t *tag = (const uint8_t *)indata + inlen; poly1305_auth(expected_tag, indata, inlen, poly_key); if (memcmp(expected_tag, tag, POLY1305_TAGLEN)) diff --git a/src/conf.c b/src/conf.c index fcaefdd2..771abe58 100644 --- a/src/conf.c +++ b/src/conf.c @@ -431,8 +431,15 @@ bool modify_config_file(struct meshlink_handle *mesh, const char *name, const ch char tmpname[PATH_MAX]; bool error = false; - snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", mesh->confbase, name); - snprintf(tmpname, sizeof(tmpname), "%s.tmp", filename); + if (snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", mesh->confbase, name) >= PATH_MAX) { + logger(mesh, MESHLINK_ERROR, "Filename too long: %s" SLASH "hosts" SLASH "%s", mesh->confbase, name); + return false; + } + + if (snprintf(tmpname, sizeof(tmpname), "%s.tmp", filename) >= PATH_MAX) { + logger(mesh, MESHLINK_ERROR, "Filename too long: %s.tmp", filename); + return false; + } FILE *fr = fopen(filename, "r"); diff --git a/src/crypto.c b/src/crypto.c index b5309b0f..1bdd8b07 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -45,8 +45,10 @@ void crypto_exit(void) { } void randomize(void *out, size_t outlen) { + char *ptr = out; + while(outlen) { - size_t len = read(random_fd, out, outlen); + size_t len = read(random_fd, ptr, outlen); if(len <= 0) { if(errno == EAGAIN || errno == EINTR) { @@ -57,7 +59,7 @@ void randomize(void *out, size_t outlen) { abort(); } - out += len; + ptr += len; outlen -= len; } } diff --git a/src/ed25519/sc.h b/src/ed25519/sc.h index 8fa727ef..e29e7fa5 100644 --- a/src/ed25519/sc.h +++ b/src/ed25519/sc.h @@ -9,4 +9,4 @@ where l = 2^252 + 27742317777372353535851937790883648493. void sc_reduce(unsigned char *s); void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c); -#endif \ No newline at end of file +#endif diff --git a/src/meshlink++.h b/src/meshlink++.h index 6a384166..20f633fd 100644 --- a/src/meshlink++.h +++ b/src/meshlink++.h @@ -174,13 +174,13 @@ public: */ /// This function is called whenever another node sends data to the local node. - virtual void receive(node *source, const void *data, size_t length) { /* do nothing */ } + virtual void receive(node *source, const void *data, size_t length) { /* do nothing */ (void)source; (void)data; (void) length; } /// This functions is called whenever another node's status changed. - virtual void node_status(node *peer, bool reachable) { /* do nothing */ } + virtual void node_status(node *peer, bool reachable) { /* do nothing */ (void)peer; (void)reachable; } /// This functions is called whenever MeshLink has some information to log. - virtual void log(log_level_t level, const char *message) { /* do nothing */ } + virtual void log(log_level_t level, const char *message) { /* do nothing */ (void)level; (void)message; } /// This functions is called whenever another node attemps to open a channel to the local node. /** @@ -203,6 +203,7 @@ public: */ virtual bool channel_accept(channel *channel, uint16_t port, const void *data, size_t len) { /* by default reject all channels */ + (void)channel; (void)port; (void)data; (void)len; return false; } @@ -217,7 +218,7 @@ public: * @param data A pointer to a buffer containing data sent by the source. * @param len The length of the data. */ - virtual void channel_receive(channel *channel, const void *data, size_t len) { /* do nothing */ } + virtual void channel_receive(channel *channel, const void *data, size_t len) { /* do nothing */ (void)channel; (void)data; (void)len; } /// This function is called by Meshlink when data can be send on a channel. /** @@ -229,7 +230,7 @@ public: * @param channel A handle for the channel. * @param len The maximum length of data that is guaranteed to be accepted by a call to channel_send(). */ - virtual void channel_poll(channel *channel, size_t len) { /* do nothing */ } + virtual void channel_poll(channel *channel, size_t len) { /* do nothing */ (void)channel; (void)len; } /// Start MeshLink. /** This function causes MeshLink to open network sockets, make outgoing connections, and diff --git a/src/meshlink.c b/src/meshlink.c index d4a833ab..61b8b561 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -641,9 +641,10 @@ static bool finalize_join(meshlink_handle_t *mesh) { static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) { (void)type; meshlink_handle_t *mesh = handle; + const char *ptr = data; while(len) { - int result = send(mesh->sock, data, len, 0); + int result = send(mesh->sock, ptr, len, 0); if(result == -1 && errno == EINTR) { continue; @@ -651,7 +652,7 @@ static bool invitation_send(void *handle, uint8_t type, const void *data, size_t return false; } - data += result; + ptr += result; len -= result; } @@ -790,7 +791,12 @@ static bool ecdsa_keygen(meshlink_handle_t *mesh) { logger(mesh, MESHLINK_DEBUG, "Done.\n"); } - snprintf(privname, sizeof(privname), "%s" SLASH "ecdsa_key.priv", mesh->confbase); + if (snprintf(privname, sizeof(privname), "%s" SLASH "ecdsa_key.priv", mesh->confbase) >= PATH_MAX) { + logger(mesh, MESHLINK_DEBUG, "Filename too long: %s" SLASH "ecdsa_key.priv\n", mesh->confbase); + meshlink_errno = MESHLINK_ESTORAGE; + return false; + } + f = fopen(privname, "wb"); if(!f) { @@ -1580,7 +1586,10 @@ static bool refresh_invitation_key(meshlink_handle_t *mesh) { char invname[PATH_MAX]; struct stat st; - snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name); + if (snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= PATH_MAX) { + logger(mesh, MESHLINK_DEBUG, "Filename too long: %s" SLASH "%s", filename, ent->d_name); + continue; + } if(!stat(invname, &st)) { if(mesh->invitation_key && deadline < st.st_mtime) { diff --git a/src/net_packet.c b/src/net_packet.c index 1ce239d9..7db041b9 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -370,7 +370,7 @@ static void send_udppacket(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *ori return; } - return send_sptps_packet(mesh, n, origpkt); + send_sptps_packet(mesh, n, origpkt); } bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len) { @@ -555,7 +555,7 @@ void handle_incoming_vpn_data(event_loop_t *loop, void *data, int flags) { listen_socket_t *ls = data; vpn_packet_t pkt; char *hostname; - sockaddr_t from = {}; + sockaddr_t from; socklen_t fromlen = sizeof(from); node_t *n; int len; diff --git a/src/net_setup.c b/src/net_setup.c index 2cd02111..f2621f3b 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -273,15 +273,13 @@ static bool add_listen_address(meshlink_handle_t *mesh, char *address, bool bind } } - struct addrinfo *ai, hint = {}; - - hint.ai_family = addressfamily; - - hint.ai_socktype = SOCK_STREAM; - - hint.ai_protocol = IPPROTO_TCP; - - hint.ai_flags = AI_PASSIVE; + struct addrinfo *ai; + struct addrinfo hint = { + .ai_family = addressfamily, + .ai_socktype = SOCK_STREAM, + .ai_protocol = IPPROTO_TCP, + .ai_flags = AI_PASSIVE, + }; int err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai); diff --git a/src/netutl.c b/src/netutl.c index f41fbecc..d38b1a18 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -32,11 +32,13 @@ bool hostnames = false; Return NULL on failure. */ struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) { - struct addrinfo *ai, hint = {}; + struct addrinfo *ai; int err; - hint.ai_family = addressfamily; - hint.ai_socktype = socktype; + struct addrinfo hint = { + .ai_family = addressfamily, + .ai_socktype = socktype, + }; err = getaddrinfo(address, service, &hint, &ai); @@ -49,13 +51,15 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock } sockaddr_t str2sockaddr(const char *address, const char *port) { - struct addrinfo *ai, hint = {}; - sockaddr_t result = {}; + struct addrinfo *ai; + sockaddr_t result; int err; - hint.ai_family = AF_UNSPEC; - hint.ai_flags = AI_NUMERICHOST; - hint.ai_socktype = SOCK_STREAM; + struct addrinfo hint = { + .ai_family = AF_UNSPEC, + .ai_flags = AI_NUMERICHOST, + .ai_socktype = SOCK_STREAM, + }; err = getaddrinfo(address, port, &hint, &ai); diff --git a/src/prf.c b/src/prf.c index ec8d0c60..499d8196 100644 --- a/src/prf.c +++ b/src/prf.c @@ -28,7 +28,7 @@ static void memxor(char *buf, char c, size_t len) { } } -static const size_t mdlen = 64; +#define mdlen 64 // TODO: separate key setup from hmac_sha512 diff --git a/src/protocol.c b/src/protocol.c index e0a0dbb2..785e20b5 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -188,9 +188,7 @@ static void age_past_requests(event_loop_t *loop, void *data) { } bool seen_request(meshlink_handle_t *mesh, const char *request) { - past_request_t *new, p = {}; - - p.request = request; + past_request_t *new, p = {.request = request}; if(splay_search(mesh->past_request_tree, &p)) { logger(mesh, MESHLINK_DEBUG, "Already seen request"); diff --git a/src/splay_tree.c b/src/splay_tree.c index 006b4d5e..e2b93a05 100644 --- a/src/splay_tree.c +++ b/src/splay_tree.c @@ -25,7 +25,7 @@ /* Splay operation */ static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *result) { - splay_node_t left = {}, right = {}; + splay_node_t left = {NULL}, right = {NULL}; splay_node_t *leftbottom = &left, *rightbottom = &right, *child, *grandchild; splay_node_t *root = tree->root; int c; diff --git a/src/sptps.c b/src/sptps.c index 3bc811ed..f44374ee 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -447,7 +447,7 @@ bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) { char buffer[len]; size_t outlen; - return chacha_poly1305_decrypt(s->incipher, seqno, data + 4, len - 4, buffer, &outlen); + return chacha_poly1305_decrypt(s->incipher, seqno, (const char *)data + 4, len - 4, buffer, &outlen); } // Receive incoming data, datagram version. @@ -561,6 +561,8 @@ bool sptps_receive_data(sptps_t *s, const void *data, size_t len) { return sptps_receive_data_datagram(s, data, len); } + const char *ptr = data; + while(len) { // First read the 2 length bytes. if(s->buflen < 2) { @@ -570,11 +572,11 @@ bool sptps_receive_data(sptps_t *s, const void *data, size_t len) { toread = len; } - memcpy(s->inbuf + s->buflen, data, toread); + memcpy(s->inbuf + s->buflen, ptr, toread); s->buflen += toread; len -= toread; - data += toread; + ptr += toread; // Exit early if we don't have the full length. if(s->buflen < 2) { @@ -606,10 +608,10 @@ bool sptps_receive_data(sptps_t *s, const void *data, size_t len) { toread = len; } - memcpy(s->inbuf + s->buflen, data, toread); + memcpy(s->inbuf + s->buflen, ptr, toread); s->buflen += toread; len -= toread; - data += toread; + ptr += toread; // If we don't have a whole record, exit. if(s->buflen < s->reclen + (s->instate ? 19UL : 3UL)) { diff --git a/src/utcp b/src/utcp index 850542e9..d0c4523c 160000 --- a/src/utcp +++ b/src/utcp @@ -1 +1 @@ -Subproject commit 850542e9585f716985c25d5995ba5bcb2cc6ba87 +Subproject commit d0c4523ccd8998a70262fb11e015ea807d4aaba7 diff --git a/test/basic.c b/test/basic.c index 30a81bcb..7b4f3cd7 100644 --- a/test/basic.c +++ b/test/basic.c @@ -5,7 +5,7 @@ #include "meshlink.h" -int main(int argc, char *argv[]) { +int main() { // Open a new meshlink instance. meshlink_handle_t *mesh = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE); diff --git a/test/basicpp.cpp b/test/basicpp.cpp index ed2815a1..4d126cf5 100644 --- a/test/basicpp.cpp +++ b/test/basicpp.cpp @@ -7,7 +7,7 @@ using namespace std; -int main(int argc, char *argv[]) { +int main() { // Open a new meshlink instance. meshlink::mesh mesh; diff --git a/test/channels-cornercases.c b/test/channels-cornercases.c index d4e02e28..ba4843d8 100644 --- a/test/channels-cornercases.c +++ b/test/channels-cornercases.c @@ -34,6 +34,9 @@ void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *tex } void a_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { + (void)mesh; + (void)channel; + if(len == 5 && !memcmp(data, "Hello", 5)) { b_responded = true; } else if(len == 0) { @@ -51,10 +54,18 @@ void b_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const vo } bool reject_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { + (void)mesh; + (void)channel; + (void)port; + (void)data; + (void)len; + return false; } bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { + (void)port; + meshlink_set_channel_accept_cb(mesh, NULL); meshlink_set_channel_receive_cb(mesh, channel, b_receive_cb); @@ -66,17 +77,22 @@ bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t po } void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { + (void)len; + meshlink_set_channel_poll_cb(mesh, channel, NULL); - set_sync_flag(channel->priv); + set_sync_flag(channel->priv, true); } void poll_cb2(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { + (void)mesh; + (void)channel; + if(len) { a_nonzero_poll_cb = true; } } -int main(int argc, char *argv[]) { +int main() { meshlink_handle_t *a, *b; open_meshlink_pair(&a, &b, "channels-cornercases"); //meshlink_set_log_cb(a, MESHLINK_DEBUG, log_cb); @@ -92,7 +108,7 @@ int main(int argc, char *argv[]) { meshlink_node_t *nb = meshlink_get_node(a, "b"); assert(nb); - struct sync_flag channel_opened = {}; + struct sync_flag channel_opened = {.flag = false}; pthread_mutex_lock(&channel_opened.mutex); meshlink_channel_t *channel = meshlink_channel_open(a, nb, 7, a_receive_cb, NULL, 0); diff --git a/test/channels-fork.c b/test/channels-fork.c index db2a033f..78d4e213 100644 --- a/test/channels-fork.c +++ b/test/channels-fork.c @@ -18,12 +18,18 @@ void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *tex } void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + (void)mesh; + if(!strcmp(node->name, "bar")) { bar_reachable = reachable; } } void foo_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { + (void)mesh; + (void)channel; + (void)len; + if(len == 5 && !memcmp(data, "Hello", 5)) { bar_responded = true; } @@ -35,6 +41,12 @@ void bar_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const } bool reject_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { + (void)mesh; + (void)channel; + (void)port; + (void)data; + (void)len; + return false; } @@ -53,6 +65,8 @@ bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t po } void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { + (void)len; + meshlink_set_channel_poll_cb(mesh, channel, NULL); if(meshlink_channel_send(mesh, channel, "Hello", 5) != 5) { @@ -210,7 +224,7 @@ int main2(int rfd, int wfd) { } -int main(int argc, char *argv[]) { +int main() { int fda[2], fdb[2]; pipe2(fda, 0); diff --git a/test/channels.c b/test/channels.c index 68512eec..c1befeec 100644 --- a/test/channels.c +++ b/test/channels.c @@ -29,6 +29,8 @@ void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *tex } void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + (void)mesh; + printf("status_cb: %s %sreachable\n", node->name, reachable ? "" : "un"); if(!strcmp(node->name, "bar")) { @@ -37,6 +39,9 @@ void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { } void foo_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { + (void)mesh; + (void)channel; + printf("foo_receive_cb %zu: ", len); fwrite(data, 1, len, stdout); printf("\n"); @@ -55,6 +60,12 @@ void bar_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const } bool reject_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { + (void)mesh; + (void)channel; + (void)port; + (void)data; + (void)len; + return false; } @@ -81,6 +92,8 @@ bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t po } void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { + (void)len; + meshlink_set_channel_poll_cb(mesh, channel, NULL); if(meshlink_channel_send(mesh, channel, "Hello", 5) != 5) { @@ -88,7 +101,7 @@ void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { } } -int main(int argc, char *argv[]) { +int main() { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Open two new meshlink instance. diff --git a/test/echo-fork.c b/test/echo-fork.c index f5aa04e3..e6aefaab 100644 --- a/test/echo-fork.c +++ b/test/echo-fork.c @@ -24,6 +24,8 @@ void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *tex } void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + (void)mesh; + if(!strcmp(node->name, "bar")) { bar_reachable = reachable; } else if(!strcmp(node->name, "foo")) @@ -33,10 +35,18 @@ void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { } void foo_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { + (void)mesh; + (void)channel; + (void)data; + (void)len; + // One way only. } void bar_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { + (void)mesh; + (void)channel; + if(!len) { fprintf(stderr, "Connection closed by foo\n"); foo_closed = true; @@ -48,6 +58,12 @@ void bar_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const } bool reject_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { + (void)mesh; + (void)channel; + (void)port; + (void)data; + (void)len; + return false; } @@ -66,6 +82,8 @@ bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t po } void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { + (void)len; + meshlink_set_channel_poll_cb(mesh, channel, NULL); bar_responded = true; } @@ -208,7 +226,7 @@ int main2(void) { } -int main(int argc, char *argv[]) { +int main() { debug_level = getenv("DEBUG") ? MESHLINK_DEBUG : MESHLINK_ERROR; // Initialize and exchange configuration. diff --git a/test/import-export.c b/test/import-export.c index 8330f05f..de2231e9 100644 --- a/test/import-export.c +++ b/test/import-export.c @@ -8,12 +8,14 @@ volatile bool bar_reachable = false; void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + (void)mesh; + if(!strcmp(node->name, "bar")) { bar_reachable = reachable; } } -int main(int argc, char *argv[]) { +int main() { // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo", "import-export", DEV_CLASS_BACKBONE); diff --git a/test/invite-join.c b/test/invite-join.c index 9f5cc806..90326a0d 100644 --- a/test/invite-join.c +++ b/test/invite-join.c @@ -8,12 +8,14 @@ volatile bool baz_reachable = false; void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + (void)mesh; + if(!strcmp(node->name, "baz")) { baz_reachable = reachable; } } -int main(int argc, char *argv[]) { +int main() { // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("invite_join_conf.1", "foo", "invite-join", DEV_CLASS_BACKBONE); diff --git a/test/sign-verify.c b/test/sign-verify.c index a9e68278..8e21b50a 100644 --- a/test/sign-verify.c +++ b/test/sign-verify.c @@ -5,7 +5,7 @@ #include "meshlink.h" -int main(int argc, char *argv[]) { +int main() { // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("sign_verify_conf.1", "foo", "sign-verify", DEV_CLASS_BACKBONE); diff --git a/test/trio.c b/test/trio.c index bfeb4f6e..2cb14bd3 100644 --- a/test/trio.c +++ b/test/trio.c @@ -12,6 +12,8 @@ #include "utils.h" static void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { + (void)mesh; + static struct timeval tv0; struct timeval tv; @@ -32,6 +34,9 @@ static void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const ch static bool received = false; static void receive_cb(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len) { + (void)mesh; + (void)source; + fprintf(stderr, "RECEIVED SOMETHING\n"); if(len == 5 && !memcmp(data, "Hello", 5)) { @@ -39,7 +44,7 @@ static void receive_cb(meshlink_handle_t *mesh, meshlink_node_t *source, const v } } -int main(int argc, char *argv[]) { +int main() { // Create three instances. const char *name[3] = {"foo", "bar", "baz"}; diff --git a/test/utils.c b/test/utils.c index 4b2b2715..862e033e 100644 --- a/test/utils.c +++ b/test/utils.c @@ -8,9 +8,9 @@ #include "utils.h" -void set_sync_flag(struct sync_flag *s) { +void set_sync_flag(struct sync_flag *s, bool value) { pthread_mutex_lock(&s->mutex); - s->flag = true; + s->flag = value; pthread_cond_broadcast(&s->cond); pthread_mutex_unlock(&s->mutex); } @@ -70,11 +70,13 @@ void open_meshlink_pair(meshlink_handle_t **pa, meshlink_handle_t **pb, const ch // Don't poll in the application thread, use a condition variable to signal when the peer is online. static void pair_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - set_sync_flag(mesh->priv); + (void)node; + + set_sync_flag(mesh->priv, reachable); } void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b) { - struct sync_flag pair_status = {}; + struct sync_flag pair_status = {.flag = false}; a->priv = &pair_status; meshlink_set_node_status_cb(a, pair_status_cb); diff --git a/test/utils.h b/test/utils.h index 9fb9b8d2..27bb38c3 100644 --- a/test/utils.h +++ b/test/utils.h @@ -10,7 +10,7 @@ struct sync_flag { bool flag; }; -extern void set_sync_flag(struct sync_flag *s); +extern void set_sync_flag(struct sync_flag *s, bool value); extern bool wait_sync_flag(struct sync_flag *s, int seconds); /// Create a pair of meshlink instances that are already joined together. -- 2.39.5