Skip to content

Commit

Permalink
build: add -Wimplicit-fallthrough
Browse files Browse the repository at this point in the history
Also:
- replace all /* fallthrough */ comments with portable fallthrough;
pseudo keyword to accomodate both gcc and clang
- add missing break; statements as required by older versions of gcc

Signed-off-by: Igor Ryzhov <[email protected]>
  • Loading branch information
idryzhov committed Oct 11, 2023
1 parent 9bc4d9e commit 87f65e1
Show file tree
Hide file tree
Showing 48 changed files with 108 additions and 95 deletions.
2 changes: 1 addition & 1 deletion bgpd/bgp_aspath.c
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ struct aspath *aspath_reconcile_as4(struct aspath *aspath,
"[AS4] AS4PATHmangle: AS_CONFED_SEQUENCE falls across 2/4 ASN boundary somewhere, broken..");
hops = seg->length;
}
/* fallthru */
fallthrough;
case AS_SEQUENCE:
cpasns = MIN(seg->length, hops);
hops -= seg->length;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,7 @@ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args,
* The following comment is to signal GCC this intention
* and suppress the warning
*/
/* FALLTHRU */
fallthrough;
case BGP_ATTR_NHLEN_IPV4:
stream_get(&attr->mp_nexthop_global_in, s, IPV4_MAX_BYTELEN);
/* Probably needed for RFC 2283 */
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_clist.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static void community_entry_free(struct community_entry *entry)
XFREE(MTYPE_COMMUNITY_LIST_CONFIG, entry->config);
if (entry->reg)
bgp_regex_free(entry->reg);
break;
default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void bgp_timer_set(struct peer_connection *connection)

EVENT_OFF(peer->connection->t_pmax_restart);
EVENT_OFF(peer->t_refresh_stalepath);
/* fallthru */
fallthrough;
case Clearing:
EVENT_OFF(connection->t_start);
EVENT_OFF(connection->t_connect);
Expand Down Expand Up @@ -2384,6 +2384,7 @@ void bgp_fsm_nht_update(struct peer_connection *connection, struct peer *peer,
&& (peer->gtsm_hops == BGP_GTSM_HOPS_CONNECTED
|| peer->bgp->fast_convergence))
BGP_EVENT_ADD(connection, TCP_fatal_error);
break;
case Clearing:
case Deleted:
case BGP_STATUS_MAX:
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ static int bgp_capability_parse(struct peer *peer, size_t length,
BGP_NOTIFY_OPEN_MALFORMED_ATTR);
return -1;
}
break;
/* we deliberately ignore unknown codes, see below */
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_routemap_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_modify(
|| IN6_IS_ADDR_LINKLOCAL(&i6a))
return NB_ERR_VALIDATION;
}
/* FALLTHROUGH */
fallthrough;
case NB_EV_PREPARE:
case NB_EV_ABORT:
return NB_OK;
Expand Down
1 change: 0 additions & 1 deletion bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ int bgp_option_set(int flag)
int bgp_option_unset(int flag)
{
switch (flag) {
/* Fall through. */
case BGP_OPT_NO_ZEBRA:
case BGP_OPT_NO_FIB:
UNSET_FLAG(bm->options, flag);
Expand Down
5 changes: 3 additions & 2 deletions bgpd/rfapi/bgp_rfapi_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ DEFUN (vnc_nve_group_export_no_routemap,
switch (argv[idx]->text[0]) {
case 'z':
is_bgp = 0;
/* fall thru */
fallthrough;
case 'b':
idx += 2;
break;
Expand Down Expand Up @@ -3590,7 +3590,8 @@ DEFUN (vnc_l2_group_rt,

switch (argv[1]->arg[0]) {
case 'b':
do_export = 1; /* fall through */
do_export = 1;
fallthrough;
case 'i':
do_import = 1;
break;
Expand Down
1 change: 1 addition & 0 deletions bgpd/rfapi/rfapi_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -4151,6 +4151,7 @@ static int rfapi_vty_show_nve_summary(struct vty *vty,

case SHOW_NVE_SUMMARY_RESPONSES:
rfapiRibShowResponsesSummary(vty);
break;

case SHOW_NVE_SUMMARY_UNKNOWN_NVES:
case SHOW_NVE_SUMMARY_MAX:
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ AC_C_FLAG([-Wpointer-arith])
AC_C_FLAG([-Wbad-function-cast])
AC_C_FLAG([-Wwrite-strings])
AC_C_FLAG([-Wundef])
AC_C_FLAG([-Wimplicit-fallthrough])
if test "$enable_gcc_ultra_verbose" = "yes" ; then
AC_C_FLAG([-Wcast-qual])
AC_C_FLAG([-Wmissing-noreturn])
Expand Down
4 changes: 2 additions & 2 deletions ldpd/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ send_capability(struct nbr *nbr, uint16_t capability, int enable)
* Announcement Parameter in Capability messages sent to
* its peers".
*/
/* FALLTHROUGH */
fallthrough;
default:
fatalx("send_capability: unsupported capability");
}
Expand Down Expand Up @@ -333,7 +333,7 @@ recv_capability(struct nbr *nbr, char *buf, uint16_t len)
* parameter and process any other Capability Parameters
* in the message".
*/
/* FALLTHROUGH */
fallthrough;
default:
if (!CHECK_FLAG(ntohs(tlv.type), UNKNOWN_FLAG))
send_notification_rtlvs(nbr, S_UNSSUPORTDCAP,
Expand Down
2 changes: 1 addition & 1 deletion ldpd/ldp_vty_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ show_lib_msg(struct vty *vty, struct imsg *imsg, struct show_params *params)
if (params->lib.remote_label != NO_LABEL &&
params->lib.remote_label != rt->remote_label)
return (0);
/* FALLTHROUGH */
fallthrough;
case IMSG_CTL_SHOW_LIB_RCVD:
rt = imsg->data;

Expand Down
4 changes: 2 additions & 2 deletions ldpd/neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,10 @@ nbr_start_idtimer(struct nbr *nbr)
break;
case 2:
secs *= 2;
/* FALLTHROUGH */
fallthrough;
case 1:
secs *= 2;
/* FALLTHROUGH */
fallthrough;
case 0:
nbr->idtimer_cnt++;
break;
Expand Down
13 changes: 8 additions & 5 deletions lib/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#endif

#include "base64.h"
#include "compiler.h"

static const int CHARS_PER_LINE = 72;
static const char *ENCODING =
Expand Down Expand Up @@ -41,6 +42,7 @@ int base64_encode_block(const char *plaintext_in, int length_in, char *code_out,

switch (state_in->step) {
while (1) {
fallthrough;
case step_A:
if (plainchar == plaintextend) {
state_in->result = result;
Expand All @@ -51,7 +53,7 @@ int base64_encode_block(const char *plaintext_in, int length_in, char *code_out,
result = (fragment & 0x0fc) >> 2;
*codechar++ = base64_encode_value(result);
result = (fragment & 0x003) << 4;
/* fall through */
fallthrough;
case step_B:
if (plainchar == plaintextend) {
state_in->result = result;
Expand All @@ -62,7 +64,7 @@ int base64_encode_block(const char *plaintext_in, int length_in, char *code_out,
result |= (fragment & 0x0f0) >> 4;
*codechar++ = base64_encode_value(result);
result = (fragment & 0x00f) << 2;
/* fall through */
fallthrough;
case step_C:
if (plainchar == plaintextend) {
state_in->result = result;
Expand Down Expand Up @@ -146,6 +148,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out,

switch (state_in->step) {
while (1) {
fallthrough;
case step_a:
do {
if (codec == code_in+length_in) {
Expand All @@ -156,7 +159,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out,
fragmt = base64_decode_value(*codec++);
} while (fragmt < 0);
*plainc = (fragmt & 0x03f) << 2;
/* fall through */
fallthrough;
case step_b:
do {
if (codec == code_in+length_in) {
Expand All @@ -168,7 +171,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out,
} while (fragmt < 0);
*plainc++ |= (fragmt & 0x030) >> 4;
*plainc = (fragmt & 0x00f) << 4;
/* fall through */
fallthrough;
case step_c:
do {
if (codec == code_in+length_in) {
Expand All @@ -180,7 +183,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out,
} while (fragmt < 0);
*plainc++ |= (fragmt & 0x03c) >> 2;
*plainc = (fragmt & 0x003) << 6;
/* fall through */
fallthrough;
case step_d:
do {
if (codec == code_in+length_in) {
Expand Down
2 changes: 1 addition & 1 deletion lib/command_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ enum matcher_rv command_complete(struct graph *graph, vector vline,
trace_matcher("trivial_match\n");
if (exact_match_exists && !last_token)
break;
/* fallthru */
fallthrough;
case exact_match:
trace_matcher("exact_match\n");
if (last_token) {
Expand Down
8 changes: 4 additions & 4 deletions lib/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
# define _RET_NONNULL , returns_nonnull
#endif
#if __has_attribute(fallthrough)
# define _FALLTHROUGH __attribute__((fallthrough));
# define fallthrough __attribute__((fallthrough));
#endif
# define _CONSTRUCTOR(x) constructor(x)
# define _DEPRECATED(x) deprecated(x)
Expand All @@ -57,7 +57,7 @@ extern "C" {
# define __has_attribute(x) 0
#endif
#if __GNUC__ >= 7
# define _FALLTHROUGH __attribute__((fallthrough));
# define fallthrough __attribute__((fallthrough));
#endif
#endif

Expand Down Expand Up @@ -112,8 +112,8 @@ extern "C" {
#ifndef _ALLOC_SIZE
# define _ALLOC_SIZE(x)
#endif
#ifndef _FALLTHROUGH
#define _FALLTHROUGH
#ifndef fallthrough
#define fallthrough
#endif
#ifndef _DEPRECATED
#define _DEPRECATED(x) deprecated
Expand Down
22 changes: 11 additions & 11 deletions lib/jhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,34 @@ uint32_t jhash(const void *key, uint32_t length, uint32_t initval)
switch (len) {
case 11:
c += ((uint32_t)k[10] << 24);
/* fallthru */
fallthrough;
case 10:
c += ((uint32_t)k[9] << 16);
/* fallthru */
fallthrough;
case 9:
c += ((uint32_t)k[8] << 8);
/* fallthru */
fallthrough;
case 8:
b += ((uint32_t)k[7] << 24);
/* fallthru */
fallthrough;
case 7:
b += ((uint32_t)k[6] << 16);
/* fallthru */
fallthrough;
case 6:
b += ((uint32_t)k[5] << 8);
/* fallthru */
fallthrough;
case 5:
b += k[4];
/* fallthru */
fallthrough;
case 4:
a += ((uint32_t)k[3] << 24);
/* fallthru */
fallthrough;
case 3:
a += ((uint32_t)k[2] << 16);
/* fallthru */
fallthrough;
case 2:
a += ((uint32_t)k[1] << 8);
/* fallthru */
fallthrough;
case 1:
a += k[0];
}
Expand Down Expand Up @@ -148,7 +148,7 @@ uint32_t jhash2(const uint32_t *k, uint32_t length, uint32_t initval)
switch (len) {
case 2:
b += k[1];
/* fallthru */
fallthrough;
case 1:
a += k[0];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/libfrr.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
break;
case '6':
path++;
/* fallthrough */
fallthrough;
default:
af = AF_INET6;
break;
Expand Down
4 changes: 2 additions & 2 deletions lib/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static int _nexthop_cmp_no_labels(const struct nexthop *next1,
ret = _nexthop_gateway_cmp(next1, next2);
if (ret != 0)
return ret;
/* Intentional Fall-Through */
fallthrough;
case NEXTHOP_TYPE_IFINDEX:
if (next1->ifindex < next2->ifindex)
return -1;
Expand Down Expand Up @@ -295,7 +295,7 @@ int nexthop_cmp_basic(const struct nexthop *nh1,
ret = nexthop_g_addr_cmp(nh1->type, &nh1->gate, &nh2->gate);
if (ret != 0)
return ret;
/* Intentional Fall-Through */
fallthrough;
case NEXTHOP_TYPE_IFINDEX:
if (nh1->ifindex < nh2->ifindex)
return -1;
Expand Down
2 changes: 1 addition & 1 deletion lib/nexthop_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static struct nexthop *nhg_nh_find(const struct nexthop_group *nhg,
&nexthop->gate, &nh->gate);
if (ret != 0)
continue;
/* Intentional Fall-Through */
fallthrough;
case NEXTHOP_TYPE_IFINDEX:
if (nexthop->ifindex != nh->ifindex)
continue;
Expand Down
Loading

0 comments on commit 87f65e1

Please sign in to comment.