Add FALLTHROUGH macro to silence -Wimplicit-fallthrough in GCC7

This commit is contained in:
Andrew Bettison 2017-09-11 12:43:38 +09:30
parent 9ba74c6767
commit 093bdfdcd3
15 changed files with 114 additions and 14 deletions

View File

@ -18,6 +18,7 @@
*/
#include "base64.h"
#include "lang.h" // for FALLTHROUGH
#include "str.h" // for Serval ctype
#include <stdint.h> // for uint8_t
#include <stdio.h> // for NULL
@ -74,6 +75,7 @@ static size_t _base64_encodev(const char symbols[], char *dstBase64, const struc
switch (place) {
case 1:
*dst++ = symbols[64];
FALLTHROUGH;
case 2:
*dst++ = symbols[64];
}

View File

@ -156,6 +156,9 @@
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if the system has the `fallthrough' statement attribute */
#undef HAVE_STMT_ATTRIBUTE_FALLTHROUGH
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H

View File

@ -18,6 +18,7 @@ AX_GCC_FUNC_ATTRIBUTE(unused)
AX_GCC_FUNC_ATTRIBUTE(used)
AX_GCC_VAR_ATTRIBUTE(section)
AX_GCC_VAR_ATTRIBUTE(section_seg)
AX_GCC_STMT_ATTRIBUTE(fallthrough)
dnl Init pkg-config
PKG_PROG_PKG_CONFIG()

View File

@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <assert.h>
#include <inttypes.h>
#include <time.h>
#include "lang.h" // for FALLTHROUGH
#include "serval_types.h"
#include "http_server.h"
#include "sighandlers.h"
@ -1185,7 +1186,7 @@ static int http_request_decode_chunks(struct http_request *r){
return WHY("Unexpected data");
return 0;
}
// fall through
FALLTHROUGH;
}
case CHUNK_SIZE:{
const char *p;
@ -1213,7 +1214,7 @@ static int http_request_decode_chunks(struct http_request *r){
r->request_content_remaining = 0;
IDEBUGF(r->debug, "EOF Chunk");
}
// fall through
FALLTHROUGH;
}
case CHUNK_DATA:{
@ -1502,7 +1503,7 @@ static int http_request_form_data_start_part(struct http_request *r, int b)
r->part_header.content_length
);
}
// fall through...
FALLTHROUGH;
case HEADER:
_INVOKE_HANDLER_VOID(handle_mime_part_end);
break;
@ -1542,7 +1543,7 @@ static int http_request_parse_body_form_data(struct http_request *r)
// The logic here allows for a missing initial CRLF before the first boundary line.
at_start = 1;
r->form_data_state = PREAMBLE;
// fall through
FALLTHROUGH;
case PREAMBLE: {
DEBUGF(http_server, "PREAMBLE");
char *start = r->parsed;
@ -2138,6 +2139,7 @@ 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;
case OPEN:
first = range->first < resource_length ? range->first : resource_length;
break;

View File

@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "lang.h" // for FALLTHROUGH
#include "serval.h"
#include "conf.h"
#include "httpd.h"
@ -175,6 +176,7 @@ static int restful_keyring_identitylist_json_content_chunk(struct http_request *
case LIST_ROWS:
strbuf_putc(b, ',');
FALLTHROUGH;
case LIST_FIRST:
r->u.sidlist.phase = LIST_ROWS;
const char *did = NULL;

9
lang.h
View File

@ -66,4 +66,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# define UNUSED(x) x
#endif
// To suppress the "may fall through" warning from -Wimplicit-fallthrough.
#ifdef HAVE_STMT_ATTRIBUTE_FALLTHROUGH
# define __ATTRIBUTE_fallthrough __fallthrough__
# define FALLTHROUGH __attribute__((__fallthrough__))
#else
# define __ATTRIBUTE_fallthrough
# define FALLTHROUGH
#endif
#endif // __SERVAL_DNA__LANG_H

View File

@ -0,0 +1,69 @@
# SYNOPSIS
#
# AX_GCC_STMT_ATTRIBUTE(ATTRIBUTE)
#
# DESCRIPTION
#
# This macro checks if the compiler supports one of GCC's statement
# attributes; many other compilers also provide statement attributes with the
# same syntax. Compiler warnings are used to detect supported attributes as
# unsupported ones are ignored by default so quieting warnings when using
# this macro will yield false positives.
#
# The ATTRIBUTE parameter holds the name of the attribute to be checked.
#
# If ATTRIBUTE is supported define HAVE_STMT_ATTRIBUTE_<ATTRIBUTE>.
#
# The macro caches its result in the ax_cv_have_stmt_attribute_<attribute>
# variable.
#
# The macro currently supports the following variable attributes:
#
# fallthrough (added 11 Sep 2017, Serval Project)
#
# LICENSE
#
# Copyright (c) 2017 Flinders University
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 3
AC_DEFUN([AX_GCC_STMT_ATTRIBUTE], [
AS_VAR_PUSHDEF([ac_var], [ax_cv_have_stmt_attribute_$1])
AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
m4_case([$1],
[fallthrough], [
int x = 1;
switch (x) {
case 0: __attribute__(($1));
case 1: break;
}
], [
m4_warn([syntax], [Unsupported attribute "$1", the test may fail])
int x = 1;
++x __attribute__(($1));
]
)])
],
dnl GCC doesn't exit with an error if an unknown attribute is
dnl provided but only outputs a warning, so accept the attribute
dnl only if no warning were issued.
[AS_IF([test -s conftest.err],
[AS_VAR_SET([ac_var], [no])],
[AS_VAR_SET([ac_var], [yes])])],
[AS_VAR_SET([ac_var], [no])
])
])
AS_IF([test yes = AS_VAR_GET([ac_var])],
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_STMT_ATTRIBUTE_$1), 1,
[Define to 1 if the system has the `$1' statement attribute])], [])
AS_VAR_POPDEF([ac_var])
])

View File

@ -1,3 +1,4 @@
#include "lang.h" // for FALLTHROUGH
#include "serval.h"
#include "serval_types.h"
#include "dataformats.h"
@ -211,13 +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;
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;
case RHIZOME_BUNDLE_STATUS_BUSY:
rhizome_bundle_result_free(&result);
rhizome_manifest_free(m);

View File

@ -1,3 +1,4 @@
#include "lang.h" // for FALLTHROUGH
#include "serval.h"
#include "dataformats.h"
#include "conf.h"
@ -339,7 +340,7 @@ static int restful_meshmb_list_json_content_chunk(struct http_request *hr, strbu
return 1;
ROWS:
case LIST_ROWS:
case LIST_ROWS: FALLTHROUGH;
case LIST_FIRST:
if (!message_ply_is_open(&r->u.plylist.ply_reader)){
@ -371,6 +372,7 @@ ROWS:
END:
r->u.plylist.phase = LIST_END;
FALLTHROUGH;
case LIST_END:
{
@ -395,7 +397,7 @@ END:
strbuf_puts(b, "\n]\n}\n");
if (!strbuf_overrun(b))
r->u.plylist.phase = LIST_DONE;
// fall through...
FALLTHROUGH;
case LIST_DONE:
return 0;
}
@ -600,7 +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:
case LIST_ROWS: FALLTHROUGH;
case LIST_FIRST:
{
struct enum_state state={
@ -613,14 +615,13 @@ static int restful_meshmb_feedlist_json_content_chunk(struct http_request *hr, s
if (meshmb_enum(r->u.meshmb_feeds.session->feeds, &r->u.meshmb_feeds.bundle_id, restful_feedlist_enum, &state)!=0)
return 0;
}
// fallthrough
r->u.meshmb_feeds.phase = LIST_END;
FALLTHROUGH;
case LIST_END:
strbuf_puts(b, "\n]\n}\n");
if (!strbuf_overrun(b))
r->u.plylist.phase = LIST_DONE;
// fall through...
FALLTHROUGH;
case LIST_DONE:
return 0;
}

View File

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdlib.h>
#include <assert.h>
#include <sys/uio.h>
#include "lang.h" // for FALLTHROUGH
#include "serval.h"
#include "conf.h"
#include "crypto.h"
@ -1397,7 +1398,7 @@ 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");
}
// fall through to set the BK field...
FALLTHROUGH; // to set the BK field...
case NEW_BUNDLE_ID:
assert(m->has_id);
// If no 'authorSidp' parameter was supplied but the manifest has a 'sender' field, then use the

View File

@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <time.h>
#include <ctype.h>
#include <assert.h>
#include "lang.h" // for FALLTHROUGH
#include "serval.h"
#include "conf.h"
#include "rhizome.h"
@ -649,6 +650,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; \
default: \
LOGF(log_level, #FUNC "(%d) failed, %s: %s", index, sqlite3_errmsg(rhizome_db), sqlite3_sql(statement)); \
sqlite3_finalize(statement); \

View File

@ -1,4 +1,5 @@
#include "lang.h" // for FALLTHROUGH
#include "rhizome.h"
#include "overlay_address.h"
#include "overlay_buffer.h"
@ -400,6 +401,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;
case RHIZOME_BUNDLE_STATUS_NEW:
// TODO we don't have this bundle anymore!
ob_rewind(payload);

View File

@ -1,3 +1,4 @@
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
/******************************************************************************
** This file is an amalgamation of many separate C source files from SQLite
** version 3.14.2. By combining all the individual C code files into this

View File

@ -65,6 +65,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <sys/uio.h>
#include <sys/socket.h>
#include <netdb.h>
#include "lang.h" // for FALLTHROUGH
#include "http_server.h"
#include "strbuf_helpers.h"
#include "str.h"
@ -491,7 +492,7 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
}
}
break;
case AF_INET:
case AF_INET: FALLTHROUGH;
case AF_INET6:{
char name[INET6_ADDRSTRLEN];
char service[6];
@ -503,7 +504,7 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
service);
break;
}
// fall through
FALLTHROUGH;
}
default: {
strbuf_append_socket_domain(sb, addr->sa_family);

2
uuid.c
View File

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "config.h"
#endif
#include "lang.h" // for FALLTHROUGH
#define __SERVAL_DNA__UUID_H_INLINE
#include "uuid.h"
#include "os.h"
@ -78,6 +79,7 @@ strbuf strbuf_uuid(strbuf sb, const serval_uuid_t *uuid)
switch (i) {
case 4: case 6: case 8: case 10:
strbuf_putc(sb, '-');
FALLTHROUGH;
default:
strbuf_putc(sb, hexdigit_lower[uuid->u.binary[i] >> 4]);
strbuf_putc(sb, hexdigit_lower[uuid->u.binary[i] & 0xf]);