From 8231c7728a62d9c9d8d3da3174360f96443fb110 Mon Sep 17 00:00:00 2001 From: Paul Gardner-Stephen Date: Fri, 10 Jul 2020 09:28:02 +0930 Subject: [PATCH] fix compilation warnings with gcc 8 --- base64.c | 11 ++++++----- directory_service.c | 2 +- http_server.c | 13 +++++++++---- keyring_restful.c | 2 +- lang.h | 7 +++++-- meshmb.c | 4 ++-- meshmb_restful.c | 14 ++++++-------- overlay_interface.c | 2 +- rhizome_bundle.c | 3 ++- rhizome_database.c | 2 +- rhizome_restful.c | 2 +- rhizome_sync_keys.c | 2 +- route_restful.c | 2 +- serval_uuid.c | 4 +++- strbuf_helpers.c | 33 +++++++++++++++++++++------------ 15 files changed, 61 insertions(+), 42 deletions(-) diff --git a/base64.c b/base64.c index 5ef6b92c..a043d8fe 100644 --- a/base64.c +++ b/base64.c @@ -73,11 +73,12 @@ static size_t _base64_encodev(const char symbols[], char *dstBase64, const struc if (place) *dst++ = symbols[buf]; switch (place) { - case 1: - *dst++ = symbols[64]; - FALLTHROUGH; - case 2: - *dst++ = symbols[64]; + case 1: + *dst++ = symbols[64]; + *dst++ = symbols[64]; + break; + case 2: + *dst++ = symbols[64]; } return dst - dstBase64; } diff --git a/directory_service.c b/directory_service.c index b555acad..7d2b7c2e 100644 --- a/directory_service.c +++ b/directory_service.c @@ -120,7 +120,7 @@ static int add_record(int mdp_sockfd){ // TODO check that did is a valid phone number - char url[256]; + char url[4096]; snprintf(url, sizeof(url), "sid://%s/local/%s|%s|%s", sid, did, did, name); // TODO only add whitelisted entries diff --git a/http_server.c b/http_server.c index 8f3bdcbe..e370e43a 100644 --- a/http_server.c +++ b/http_server.c @@ -1212,8 +1212,9 @@ static int http_request_decode_chunks(struct http_request *r){ return WHY("Unexpected data"); return 0; } - FALLTHROUGH; } + FALLTHROUGH; + // fall through case CHUNK_SIZE:{ const char *p; // TODO fail on non hex input @@ -1240,8 +1241,9 @@ static int http_request_decode_chunks(struct http_request *r){ r->request_content_remaining = 0; IDEBUGF(r->debug, "EOF Chunk"); } - FALLTHROUGH; } + FALLTHROUGH; + // fall through case CHUNK_DATA:{ // Skip over the chunk heading if we can, to avoid a memmove. if (r->end_decoded == r->parsed) @@ -1531,7 +1533,8 @@ static int http_request_form_data_start_part(struct http_request *r, int b) r->part_header.content_length ); } - FALLTHROUGH; + _INVOKE_HANDLER_VOID(handle_mime_part_end); + break; case HEADER: _INVOKE_HANDLER_VOID(handle_mime_part_end); break; @@ -1572,6 +1575,7 @@ static int http_request_parse_body_form_data(struct http_request *r) at_start = 1; r->form_data_state = PREAMBLE; FALLTHROUGH; + // fall through case PREAMBLE: { DEBUGF(http_server, "PREAMBLE"); char *start = r->parsed; @@ -2165,7 +2169,8 @@ unsigned http_range_close(struct http_range *dst, const struct http_range *src, switch (range->type) { case CLOSED: last = range->last < resource_length ? range->last : resource_length - 1; - FALLTHROUGH; + first = range->first < resource_length ? range->first : resource_length; + break; case OPEN: first = range->first < resource_length ? range->first : resource_length; break; diff --git a/keyring_restful.c b/keyring_restful.c index 43bb8cdb..7fe9981c 100644 --- a/keyring_restful.c +++ b/keyring_restful.c @@ -177,7 +177,7 @@ static int restful_keyring_identitylist_json_content_chunk(struct http_request * case LIST_ROWS: strbuf_putc(b, ','); - FALLTHROUGH; + FALLTHROUGH; // fall through case LIST_FIRST: r->u.sidlist.phase = LIST_ROWS; const char *did = NULL; diff --git a/lang.h b/lang.h index 89888344..2586828e 100644 --- a/lang.h +++ b/lang.h @@ -78,10 +78,13 @@ typedef char bool_t; // To suppress the "may fall through" warning from -Wimplicit-fallthrough. #ifdef HAVE_STMT_ATTRIBUTE_FALLTHROUGH # define __ATTRIBUTE_fallthrough __fallthrough__ -# define FALLTHROUGH __attribute__((__fallthrough__)) +# define FALLTHROUGH __attribute__((__fallthrough__)); #else # define __ATTRIBUTE_fallthrough -# define FALLTHROUGH +// If there is no __fallthrough__ attribute, it is a bit of a pain, because +// not all version of GCC will let us define the fall-through comment in a macro +// like this for portability. +# define FALLTHROUGH // fall-through #endif #endif // __SERVAL_DNA__LANG_H diff --git a/meshmb.c b/meshmb.c index ac716198..6fc4c6c2 100644 --- a/meshmb.c +++ b/meshmb.c @@ -212,14 +212,14 @@ static int activity_ack(struct meshmb_feeds *feeds, struct message_ply_ack *ack) case RHIZOME_BUNDLE_STATUS_NEW: rhizome_manifest_set_tail(m, 0); rhizome_manifest_set_filesize(m, 0); - FALLTHROUGH; + FALLTHROUGH; // fall through case RHIZOME_BUNDLE_STATUS_SAME: { enum rhizome_payload_status pstatus = rhizome_write_open_journal(&feeds->ack_writer, m, 0, RHIZOME_SIZE_UNSET); if (pstatus==RHIZOME_PAYLOAD_STATUS_NEW) break; } - FALLTHROUGH; + FALLTHROUGH; // fall through case RHIZOME_BUNDLE_STATUS_BUSY: rhizome_bundle_result_free(&result); rhizome_manifest_free(m); diff --git a/meshmb_restful.c b/meshmb_restful.c index c1bbc024..6b9a6282 100644 --- a/meshmb_restful.c +++ b/meshmb_restful.c @@ -341,8 +341,7 @@ static int restful_meshmb_list_json_content_chunk(struct http_request *hr, strbu return 1; ROWS: - case LIST_ROWS: FALLTHROUGH; - case LIST_FIRST: + case LIST_ROWS: case LIST_FIRST: if (!message_ply_is_open(&r->u.plylist.ply_reader)){ // re-load the current message text @@ -373,7 +372,7 @@ ROWS: END: r->u.plylist.phase = LIST_END; - FALLTHROUGH; + FALLTHROUGH; // fall through case LIST_END: { @@ -398,7 +397,7 @@ END: strbuf_puts(b, "\n]\n}\n"); if (!strbuf_overrun(b)) r->u.plylist.phase = LIST_DONE; - FALLTHROUGH; + FALLTHROUGH; // fall through case LIST_DONE: return 0; } @@ -603,8 +602,7 @@ static int restful_meshmb_feedlist_json_content_chunk(struct http_request *hr, s r->u.meshmb_feeds.phase = LIST_ROWS; return 1; - case LIST_ROWS: FALLTHROUGH; - case LIST_FIRST: + case LIST_ROWS: case LIST_FIRST: { struct enum_state state={ .request = r, @@ -617,12 +615,12 @@ static int restful_meshmb_feedlist_json_content_chunk(struct http_request *hr, s return 0; } r->u.meshmb_feeds.phase = LIST_END; - FALLTHROUGH; + FALLTHROUGH; // fall through case LIST_END: strbuf_puts(b, "\n]\n}\n"); if (!strbuf_overrun(b)) r->u.plylist.phase = LIST_DONE; - FALLTHROUGH; + FALLTHROUGH; // fall through case LIST_DONE: return 0; } diff --git a/overlay_interface.c b/overlay_interface.c index f39d84b2..703d74bd 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -1496,7 +1496,7 @@ static void file_interface_init(const struct config_network_interface *ifconfig) broadcast.inet.sin_port=htons(ifconfig->port); broadcast.inet.sin_addr.s_addr=ifconfig->dummy_address.s_addr | ~ifconfig->dummy_netmask.s_addr; - FALLTHROUGH; + FALLTHROUGH; // fall through case SOCK_STREAM: if (!form_dummy_file_path(file_path, sizeof file_path, ifconfig->file)) return; // ignore if path is too long diff --git a/rhizome_bundle.c b/rhizome_bundle.c index 8f2f1e87..bad6694e 100644 --- a/rhizome_bundle.c +++ b/rhizome_bundle.c @@ -1399,7 +1399,8 @@ struct rhizome_bundle_result rhizome_fill_manifest(rhizome_manifest *m, const ch if (rhizome_manifest_createid(m) == -1) { return rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_ERROR, "Could not bind manifest to an ID"); } - FALLTHROUGH; // to set the BK field... + // to set the BK field... + FALLTHROUGH; // fall through case NEW_BUNDLE_ID: assert(m->has_id); // If the manifest has no author but does have a 'sender' field, then use the diff --git a/rhizome_database.c b/rhizome_database.c index 24886987..6bc534cf 100644 --- a/rhizome_database.c +++ b/rhizome_database.c @@ -702,7 +702,7 @@ int _sqlite_vbind(struct __sourceloc __whence, int log_level, sqlite_retry_state case SQLITE_LOCKED: \ if (retry && _sqlite_retry(__whence, retry, #FUNC "()")) \ continue; \ - FALLTHROUGH; \ + FALLTHROUGH; /* fall through */ \ default: \ LOGF(log_level, #FUNC "(%d) failed, %s: %s", index, sqlite3_errmsg(rhizome_database.db), sqlite3_sql(statement)); \ sqlite3_finalize(statement); \ diff --git a/rhizome_restful.c b/rhizome_restful.c index 18ae9fed..ffca5e82 100644 --- a/rhizome_restful.c +++ b/rhizome_restful.c @@ -585,7 +585,7 @@ static int insert_make_manifest(httpd_request *r) break; default: WHYF("rhizome_manifest_parse() returned %d", n); - FALLTHROUGH; + FALLTHROUGH; // fall through case -1: r->bundle_result = rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_ERROR, "Internal error while parsing manifest"); break; diff --git a/rhizome_sync_keys.c b/rhizome_sync_keys.c index d8d16bfe..ae7bf7b4 100644 --- a/rhizome_sync_keys.c +++ b/rhizome_sync_keys.c @@ -430,7 +430,7 @@ static void sync_send_peer(struct subscriber *peer, struct rhizome_sync_keys *sy DEBUGF(rhizome_sync_keys, "Can't send manifest right now, (hash %s) %s", alloca_sync_key(&msg->key), rhizome_bundle_status_message_nonnull(status)); - FALLTHROUGH; + FALLTHROUGH; // fall through case RHIZOME_BUNDLE_STATUS_NEW: // TODO we don't have this bundle anymore! ob_rewind(payload); diff --git a/route_restful.c b/route_restful.c index 63fdf834..50d26042 100644 --- a/route_restful.c +++ b/route_restful.c @@ -104,7 +104,7 @@ static int restful_route_list_json_content_chunk(struct http_request *hr, strbuf case LIST_ROWS: strbuf_putc(b, ','); - FALLTHROUGH; + FALLTHROUGH; // fall through case LIST_FIRST: r->u.subscriberlist.phase = LIST_ROWS; struct subscriber **subscriberp = subscriber_iterator_get_current(&r->u.subscriberlist.it); diff --git a/serval_uuid.c b/serval_uuid.c index e916f2fb..8ca6994c 100644 --- a/serval_uuid.c +++ b/serval_uuid.c @@ -79,7 +79,9 @@ strbuf strbuf_uuid(strbuf sb, const serval_uuid_t *uuid) switch (i) { case 4: case 6: case 8: case 10: strbuf_putc(sb, '-'); - FALLTHROUGH; + strbuf_putc(sb, hexdigit_lower[uuid->u.binary[i] >> 4]); + strbuf_putc(sb, hexdigit_lower[uuid->u.binary[i] & 0xf]); + break; default: strbuf_putc(sb, hexdigit_lower[uuid->u.binary[i] >> 4]); strbuf_putc(sb, hexdigit_lower[uuid->u.binary[i] & 0xf]); diff --git a/strbuf_helpers.c b/strbuf_helpers.c index 4a1f9239..db86c1a0 100644 --- a/strbuf_helpers.c +++ b/strbuf_helpers.c @@ -494,19 +494,28 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t } break; case AF_INET: FALLTHROUGH; - case AF_INET6:{ - char name[INET6_ADDRSTRLEN]; - char service[6]; - - if (getnameinfo(addr, addrlen, name, sizeof name, service, sizeof service, NI_NUMERICHOST|NI_NUMERICSERV)==0){ - strbuf_sprintf(sb, "%s:%s:%s", - addr->sa_family==AF_INET?"AF_INET":"AF_INET6", - name, - service); - break; + case AF_INET6: + { + char name[INET6_ADDRSTRLEN]; + char service[6]; + + if (getnameinfo(addr, addrlen, name, sizeof name, service, sizeof service, NI_NUMERICHOST|NI_NUMERICSERV)==0){ + strbuf_sprintf(sb, "%s:%s:%s", + addr->sa_family==AF_INET?"AF_INET":"AF_INET6", + name, + service); + break; + } + + strbuf_append_socket_domain(sb, addr->sa_family); + size_t len = (size_t)addrlen > sizeof addr->sa_family ? addrlen - sizeof addr->sa_family : 0; + unsigned i; + for (i = 0; i < len; ++i) { + strbuf_putc(sb, i ? ',' : ':'); + strbuf_sprintf(sb, "%02x", addr->sa_data[i]); + } } - FALLTHROUGH; - } + break; default: { strbuf_append_socket_domain(sb, addr->sa_family); size_t len = (size_t)addrlen > sizeof addr->sa_family ? addrlen - sizeof addr->sa_family : 0;