From a8b88a462f3e2fc37cf77f682f3c5c17ee313278 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Fri, 12 Apr 2013 17:16:50 +0930 Subject: [PATCH] Fix clang compiler warnings (revealed some bugs) --- cli.h | 2 +- commandline.c | 2 +- conf_schema.h | 2 +- mdp_client.c | 4 ++-- overlay_mdp.c | 8 +------- overlay_packetformats.c | 19 ++++++++++--------- serval.h | 3 ++- 7 files changed, 18 insertions(+), 22 deletions(-) diff --git a/cli.h b/cli.h index ec25bad5..3ef3b14e 100644 --- a/cli.h +++ b/cli.h @@ -46,7 +46,7 @@ struct cli_parsed { unsigned labelc; const char *const *args; unsigned argc; - unsigned varargi; + int varargi; // -1 means no var args }; void _debug_cli_parsed(struct __sourceloc __whence, const struct cli_parsed *parsed); diff --git a/commandline.c b/commandline.c index 844d1abf..3b5441e6 100644 --- a/commandline.c +++ b/commandline.c @@ -1927,7 +1927,7 @@ int app_count_peers(const struct cli_parsed *parsed, void *context) bzero(&a, sizeof(overlay_mdp_frame)); a.packetTypeAndFlags=MDP_GETADDRS; a.addrlist.mode = MDP_ADDRLIST_MODE_ROUTABLE_PEERS; - a.addrlist.first_sid=0x7fffffff; + a.addrlist.first_sid = OVERLAY_MDP_ADDRLIST_MAX_SID_COUNT; if (overlay_mdp_send(&a,MDP_AWAITREPLY,5000)){ if (a.packetTypeAndFlags==MDP_ERROR) return WHYF(" MDP Server error #%d: '%s'",a.error.error,a.error.message); diff --git a/conf_schema.h b/conf_schema.h index c756010f..565ebf8b 100644 --- a/conf_schema.h +++ b/conf_schema.h @@ -315,7 +315,7 @@ ATOM(uint32_t, uid, 0, uint32_nonzero,, "Allowed UID for mon END_STRUCT STRUCT(mdp_iftype) -ATOM(uint32_t, tick_ms, -1, uint32_nonzero,, "Tick interval for this interface type") +ATOM(int32_t, tick_ms, -1, int32_nonneg,, "Tick interval for this interface type") ATOM(int32_t, packet_interval, -1, int32_nonneg,, "Minimum interval between packets in microseconds") END_STRUCT diff --git a/mdp_client.c b/mdp_client.c index 43281925..31195a7c 100644 --- a/mdp_client.c +++ b/mdp_client.c @@ -250,7 +250,7 @@ int overlay_mdp_bind(const sid_t *localaddr, int port) return 0; } -int overlay_mdp_getmyaddr(int index, sid_t *sid) +int overlay_mdp_getmyaddr(unsigned index, sid_t *sid) { overlay_mdp_frame a; memset(&a, 0, sizeof(a)); @@ -258,7 +258,7 @@ int overlay_mdp_getmyaddr(int index, sid_t *sid) a.packetTypeAndFlags=MDP_GETADDRS; a.addrlist.mode = MDP_ADDRLIST_MODE_SELF; a.addrlist.first_sid=index; - a.addrlist.last_sid=0x7fffffff; + a.addrlist.last_sid=OVERLAY_MDP_ADDRLIST_MAX_SID_COUNT; a.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST; int result=overlay_mdp_send(&a,MDP_AWAITREPLY,5000); if (result) { diff --git a/overlay_mdp.c b/overlay_mdp.c index 97be60e8..efe58a92 100644 --- a/overlay_mdp.c +++ b/overlay_mdp.c @@ -794,19 +794,13 @@ static int search_subscribers(struct subscriber *subscriber, void *context){ int overlay_mdp_address_list(overlay_mdp_addrlist *request, overlay_mdp_addrlist *response){ if (config.debug.mdprequests) - DEBUGF("MDP_GETADDRS first_sid=%u mode=%d", - request->first_sid, - request->mode - ); + DEBUGF("MDP_GETADDRS first_sid=%u mode=%d", request->first_sid, request->mode); /* Prepare reply packet */ response->mode = request->mode; response->first_sid = request->first_sid; response->frame_sid_count = 0; - /* ... and constrain list for sanity */ - if (response->first_sid<0) response->first_sid=0; - /* Populate with SIDs */ enum_subscribers(NULL, search_subscribers, response); diff --git a/overlay_packetformats.c b/overlay_packetformats.c index 2d2ab88a..8aede502 100644 --- a/overlay_packetformats.c +++ b/overlay_packetformats.c @@ -112,13 +112,13 @@ int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, s // duplicate the frame and queue it int overlay_forward_payload(struct overlay_frame *f){ IN(); - if (f->ttl<=0) + if (f->ttl == 0) RETURN(0); if (config.debug.overlayframes) - DEBUGF("Forwarding payload for %s, ttl=%d", + DEBUGF("Forwarding payload for %s, ttl=%u", (f->destination?alloca_tohex_sid(f->destination->sid):"broadcast"), - f->ttl); + (unsigned)f->ttl); /* Queue frame for dispatch. Don't forget to put packet in the correct queue based on type. @@ -212,17 +212,18 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f frame->ttl = ttl_qos & 0x1F; frame->queue = (ttl_qos >> 5) & 3; } - frame->ttl--; - if (frame->ttl<=0){ - forward=0; + if (frame->ttl == 0){ + forward = 0; if (config.debug.overlayframes) DEBUGF("Don't forward when TTL expired"); - } + } else + --frame->ttl; if (flags & PAYLOAD_FLAG_LEGACY_TYPE){ - frame->type=ob_get(buffer); - if (frame->type<0) + int ftype = ob_get(buffer); + if (ftype == -1) RETURN(WHY("Unable to read type")); + frame->type = ftype; }else frame->type=OF_TYPE_DATA; diff --git a/serval.h b/serval.h index 35f4d524..3e53dc79 100644 --- a/serval.h +++ b/serval.h @@ -622,6 +622,7 @@ typedef struct overlay_mdp_error { typedef struct overlay_mdp_addrlist { int mode; +#define OVERLAY_MDP_ADDRLIST_MAX_SID_COUNT (~(unsigned int)0) unsigned int server_sid_count; unsigned int first_sid; unsigned int last_sid; @@ -693,7 +694,7 @@ void cli_put_long(int64_t value, const char *delim); void cli_put_string(const char *value, const char *delim); void cli_put_hexvalue(const unsigned char *value, int length, const char *delim); -int overlay_mdp_getmyaddr(int index, sid_t *sid); +int overlay_mdp_getmyaddr(unsigned index, sid_t *sid); int overlay_mdp_bind(const sid_t *localaddr, int port) ; int overlay_route_node_info(overlay_mdp_nodeinfo *node_info); int overlay_interface_register(char *name,