From 7099a4437e84740d2e5cc6242561b3fd894ff802 Mon Sep 17 00:00:00 2001 From: thorkill Date: Mon, 29 Jun 2015 19:42:23 +0200 Subject: [PATCH] Fixing implicit conversion changes to signedness - format string - function parameters - logging --- src/logger.c | 4 ++-- src/meta.c | 19 ++++++++++++------- src/meta.h | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/logger.c b/src/logger.c index 2fbb9095..9e060dec 100644 --- a/src/logger.c +++ b/src/logger.c @@ -96,8 +96,8 @@ static void real_logger(int level, int priority, const char *message) { logcontrol = true; if(level > (c->outcompression >= 0 ? (int)c->outcompression : (int)debug_level)) continue; - int len = strlen(message); - if(send_request(c, "%d %d %d", CONTROL, REQ_LOG, len)) + size_t len = strlen(message); + if(send_request(c, "%d %d %zu", CONTROL, REQ_LOG, len)) send_meta(c, message, len); } suppress = false; diff --git a/src/meta.c b/src/meta.c index 35672a78..d09c9a58 100644 --- a/src/meta.c +++ b/src/meta.c @@ -48,17 +48,22 @@ bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t leng return true; } -bool send_meta(connection_t *c, const char *buffer, int length) { +bool send_meta(connection_t *c, const char *buffer, size_t length) { if(!c) { logger(DEBUG_ALWAYS, LOG_ERR, "send_meta() called with NULL pointer!"); abort(); } - logger(DEBUG_META, LOG_DEBUG, "Sending %d bytes of metadata to %s (%s)", length, + logger(DEBUG_META, LOG_DEBUG, "Sending %zu bytes of metadata to %s (%s)", length, c->name, c->hostname); - if(c->protocol_minor >= 2) - return sptps_send_record(&c->sptps, 0, buffer, length); + if(c->protocol_minor >= 2) { + if (length > UINT16_MAX) { + logger(DEBUG_ALWAYS, LOG_ERR, "send_meta() aborting due to length %zu >= %d!", length, UINT16_MAX); + abort(); + } + return sptps_send_record(&c->sptps, 0, buffer, (uint16_t)length); + } /* Add our data to buffer */ if(c->status.encryptout) { @@ -82,13 +87,13 @@ bool send_meta(connection_t *c, const char *buffer, int length) { return true; } -void send_meta_raw(connection_t *c, const char *buffer, int length) { +void send_meta_raw(connection_t *c, const char *buffer, size_t length) { if(!c) { logger(DEBUG_ALWAYS, LOG_ERR, "send_meta() called with NULL pointer!"); abort(); } - logger(DEBUG_META, LOG_DEBUG, "Sending %d bytes of raw metadata to %s (%s)", length, + logger(DEBUG_META, LOG_DEBUG, "Sending %zu bytes of raw metadata to %s (%s)", length, c->name, c->hostname); buffer_add(&c->outbuf, buffer, length); @@ -96,7 +101,7 @@ void send_meta_raw(connection_t *c, const char *buffer, int length) { io_set(&c->io, IO_READ | IO_WRITE); } -void broadcast_meta(connection_t *from, const char *buffer, int length) { +void broadcast_meta(connection_t *from, const char *buffer, size_t length) { for list_each(connection_t, c, connection_list) if(c != from && c->edge) send_meta(c, buffer, length); diff --git a/src/meta.h b/src/meta.h index 8b00a5ab..4ec36fff 100644 --- a/src/meta.h +++ b/src/meta.h @@ -23,11 +23,11 @@ #include "connection.h" -extern bool send_meta(struct connection_t *, const char *, int); -extern void send_meta_raw(struct connection_t *, const char *, int); +extern bool send_meta(struct connection_t *, const char *, size_t); +extern void send_meta_raw(struct connection_t *, const char *, size_t); extern bool send_meta_sptps(void *, uint8_t, const void *, size_t); extern bool receive_meta_sptps(void *, uint8_t, const void *, uint16_t); -extern void broadcast_meta(struct connection_t *, const char *, int); +extern void broadcast_meta(struct connection_t *, const char *, size_t); extern bool receive_meta(struct connection_t *); #endif /* __TINC_META_H__ */