Skip to content

Commit 7d67b9f

Browse files
committed
build: add -Wimplicit-fallthrough
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 - cleanup some code to remove unnecessary fallthrough Signed-off-by: Igor Ryzhov <[email protected]>
1 parent 9bc4d9e commit 7d67b9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+114
-110
lines changed

bgpd/bgp_aspath.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ struct aspath *aspath_reconcile_as4(struct aspath *aspath,
18921892
"[AS4] AS4PATHmangle: AS_CONFED_SEQUENCE falls across 2/4 ASN boundary somewhere, broken..");
18931893
hops = seg->length;
18941894
}
1895-
/* fallthru */
1895+
fallthrough;
18961896
case AS_SEQUENCE:
18971897
cpasns = MIN(seg->length, hops);
18981898
hops -= seg->length;

bgpd/bgp_attr.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -2323,11 +2323,8 @@ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args,
23232323
/*
23242324
* NOTE: intentional fall through
23252325
* - for consistency in rx processing
2326-
*
2327-
* The following comment is to signal GCC this intention
2328-
* and suppress the warning
23292326
*/
2330-
/* FALLTHRU */
2327+
fallthrough;
23312328
case BGP_ATTR_NHLEN_IPV4:
23322329
stream_get(&attr->mp_nexthop_global_in, s, IPV4_MAX_BYTELEN);
23332330
/* Probably needed for RFC 2283 */

bgpd/bgp_clist.c

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static void community_entry_free(struct community_entry *entry)
128128
XFREE(MTYPE_COMMUNITY_LIST_CONFIG, entry->config);
129129
if (entry->reg)
130130
bgp_regex_free(entry->reg);
131+
break;
131132
default:
132133
break;
133134
}

bgpd/bgp_fsm.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ void bgp_timer_set(struct peer_connection *connection)
445445

446446
EVENT_OFF(peer->connection->t_pmax_restart);
447447
EVENT_OFF(peer->t_refresh_stalepath);
448-
/* fallthru */
448+
fallthrough;
449449
case Clearing:
450450
EVENT_OFF(connection->t_start);
451451
EVENT_OFF(connection->t_connect);
@@ -2384,6 +2384,7 @@ void bgp_fsm_nht_update(struct peer_connection *connection, struct peer *peer,
23842384
&& (peer->gtsm_hops == BGP_GTSM_HOPS_CONNECTED
23852385
|| peer->bgp->fast_convergence))
23862386
BGP_EVENT_ADD(connection, TCP_fatal_error);
2387+
break;
23872388
case Clearing:
23882389
case Deleted:
23892390
case BGP_STATUS_MAX:

bgpd/bgp_open.c

+1
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ static int bgp_capability_parse(struct peer *peer, size_t length,
10281028
BGP_NOTIFY_OPEN_MALFORMED_ATTR);
10291029
return -1;
10301030
}
1031+
break;
10311032
/* we deliberately ignore unknown codes, see below */
10321033
default:
10331034
break;

bgpd/bgp_routemap_nb_config.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_modify(
17471747
|| IN6_IS_ADDR_LINKLOCAL(&i6a))
17481748
return NB_ERR_VALIDATION;
17491749
}
1750-
/* FALLTHROUGH */
1750+
return NB_OK;
17511751
case NB_EV_PREPARE:
17521752
case NB_EV_ABORT:
17531753
return NB_OK;

bgpd/bgpd.c

-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ int bgp_option_set(int flag)
186186
int bgp_option_unset(int flag)
187187
{
188188
switch (flag) {
189-
/* Fall through. */
190189
case BGP_OPT_NO_ZEBRA:
191190
case BGP_OPT_NO_FIB:
192191
UNSET_FLAG(bm->options, flag);

bgpd/rfapi/bgp_rfapi_cfg.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,8 @@ DEFUN (vnc_nve_group_export_no_routemap,
17201720
switch (argv[idx]->text[0]) {
17211721
case 'z':
17221722
is_bgp = 0;
1723-
/* fall thru */
1723+
idx += 2;
1724+
break;
17241725
case 'b':
17251726
idx += 2;
17261727
break;
@@ -3590,7 +3591,9 @@ DEFUN (vnc_l2_group_rt,
35903591

35913592
switch (argv[1]->arg[0]) {
35923593
case 'b':
3593-
do_export = 1; /* fall through */
3594+
do_export = 1;
3595+
do_import = 1;
3596+
break;
35943597
case 'i':
35953598
do_import = 1;
35963599
break;

bgpd/rfapi/rfapi_vty.c

+1
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,7 @@ static int rfapi_vty_show_nve_summary(struct vty *vty,
41514151

41524152
case SHOW_NVE_SUMMARY_RESPONSES:
41534153
rfapiRibShowResponsesSummary(vty);
4154+
break;
41544155

41554156
case SHOW_NVE_SUMMARY_UNKNOWN_NVES:
41564157
case SHOW_NVE_SUMMARY_MAX:

configure.ac

+1
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ AC_C_FLAG([-Wpointer-arith])
365365
AC_C_FLAG([-Wbad-function-cast])
366366
AC_C_FLAG([-Wwrite-strings])
367367
AC_C_FLAG([-Wundef])
368+
AC_C_FLAG([-Wimplicit-fallthrough])
368369
if test "$enable_gcc_ultra_verbose" = "yes" ; then
369370
AC_C_FLAG([-Wcast-qual])
370371
AC_C_FLAG([-Wmissing-noreturn])

ldpd/init.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ send_capability(struct nbr *nbr, uint16_t capability, int enable)
229229
* Announcement Parameter in Capability messages sent to
230230
* its peers".
231231
*/
232-
/* FALLTHROUGH */
232+
fallthrough;
233233
default:
234234
fatalx("send_capability: unsupported capability");
235235
}
@@ -333,7 +333,7 @@ recv_capability(struct nbr *nbr, char *buf, uint16_t len)
333333
* parameter and process any other Capability Parameters
334334
* in the message".
335335
*/
336-
/* FALLTHROUGH */
336+
fallthrough;
337337
default:
338338
if (!CHECK_FLAG(ntohs(tlv.type), UNKNOWN_FLAG))
339339
send_notification_rtlvs(nbr, S_UNSSUPORTDCAP,

ldpd/ldp_vty_exec.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ show_lib_msg(struct vty *vty, struct imsg *imsg, struct show_params *params)
11061106
if (params->lib.remote_label != NO_LABEL &&
11071107
params->lib.remote_label != rt->remote_label)
11081108
return (0);
1109-
/* FALLTHROUGH */
1109+
fallthrough;
11101110
case IMSG_CTL_SHOW_LIB_RCVD:
11111111
rt = imsg->data;
11121112

ldpd/neighbor.c

+3-12
Original file line numberDiff line numberDiff line change
@@ -505,21 +505,12 @@ nbr_start_idtimer(struct nbr *nbr)
505505
{
506506
int secs;
507507

508-
secs = INIT_DELAY_TMR;
509-
switch(nbr->idtimer_cnt) {
510-
default:
508+
if (nbr->idtimer_cnt > 2) {
511509
/* do not further increase the counter */
512510
secs = MAX_DELAY_TMR;
513-
break;
514-
case 2:
515-
secs *= 2;
516-
/* FALLTHROUGH */
517-
case 1:
518-
secs *= 2;
519-
/* FALLTHROUGH */
520-
case 0:
511+
} else {
512+
secs = INIT_DELAY_TMR * (1 << nbr->idtimer_cnt);
521513
nbr->idtimer_cnt++;
522-
break;
523514
}
524515

525516
EVENT_OFF(nbr->initdelay_timer);

lib/base64.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#endif
1010

1111
#include "base64.h"
12+
#include "compiler.h"
1213

1314
static const int CHARS_PER_LINE = 72;
1415
static const char *ENCODING =
@@ -41,6 +42,7 @@ int base64_encode_block(const char *plaintext_in, int length_in, char *code_out,
4142

4243
switch (state_in->step) {
4344
while (1) {
45+
fallthrough;
4446
case step_A:
4547
if (plainchar == plaintextend) {
4648
state_in->result = result;
@@ -51,7 +53,7 @@ int base64_encode_block(const char *plaintext_in, int length_in, char *code_out,
5153
result = (fragment & 0x0fc) >> 2;
5254
*codechar++ = base64_encode_value(result);
5355
result = (fragment & 0x003) << 4;
54-
/* fall through */
56+
fallthrough;
5557
case step_B:
5658
if (plainchar == plaintextend) {
5759
state_in->result = result;
@@ -62,7 +64,7 @@ int base64_encode_block(const char *plaintext_in, int length_in, char *code_out,
6264
result |= (fragment & 0x0f0) >> 4;
6365
*codechar++ = base64_encode_value(result);
6466
result = (fragment & 0x00f) << 2;
65-
/* fall through */
67+
fallthrough;
6668
case step_C:
6769
if (plainchar == plaintextend) {
6870
state_in->result = result;
@@ -146,6 +148,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out,
146148

147149
switch (state_in->step) {
148150
while (1) {
151+
fallthrough;
149152
case step_a:
150153
do {
151154
if (codec == code_in+length_in) {
@@ -156,7 +159,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out,
156159
fragmt = base64_decode_value(*codec++);
157160
} while (fragmt < 0);
158161
*plainc = (fragmt & 0x03f) << 2;
159-
/* fall through */
162+
fallthrough;
160163
case step_b:
161164
do {
162165
if (codec == code_in+length_in) {
@@ -168,7 +171,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out,
168171
} while (fragmt < 0);
169172
*plainc++ |= (fragmt & 0x030) >> 4;
170173
*plainc = (fragmt & 0x00f) << 4;
171-
/* fall through */
174+
fallthrough;
172175
case step_c:
173176
do {
174177
if (codec == code_in+length_in) {
@@ -180,7 +183,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out,
180183
} while (fragmt < 0);
181184
*plainc++ |= (fragmt & 0x03c) >> 2;
182185
*plainc = (fragmt & 0x003) << 6;
183-
/* fall through */
186+
fallthrough;
184187
case step_d:
185188
do {
186189
if (codec == code_in+length_in) {

lib/command_match.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@ enum matcher_rv command_complete(struct graph *graph, vector vline,
405405
listnode_add(next, newstack);
406406
break;
407407
case partly_match:
408-
trace_matcher("trivial_match\n");
408+
trace_matcher("partly_match\n");
409409
if (exact_match_exists && !last_token)
410410
break;
411-
/* fallthru */
411+
fallthrough;
412412
case exact_match:
413413
trace_matcher("exact_match\n");
414414
if (last_token) {

lib/compiler.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333
# define _RET_NONNULL , returns_nonnull
3434
#endif
3535
#if __has_attribute(fallthrough)
36-
# define _FALLTHROUGH __attribute__((fallthrough));
36+
# define fallthrough __attribute__((fallthrough));
3737
#endif
3838
# define _CONSTRUCTOR(x) constructor(x)
3939
# define _DEPRECATED(x) deprecated(x)
@@ -57,7 +57,7 @@ extern "C" {
5757
# define __has_attribute(x) 0
5858
#endif
5959
#if __GNUC__ >= 7
60-
# define _FALLTHROUGH __attribute__((fallthrough));
60+
# define fallthrough __attribute__((fallthrough));
6161
#endif
6262
#endif
6363

@@ -112,8 +112,8 @@ extern "C" {
112112
#ifndef _ALLOC_SIZE
113113
# define _ALLOC_SIZE(x)
114114
#endif
115-
#ifndef _FALLTHROUGH
116-
#define _FALLTHROUGH
115+
#ifndef fallthrough
116+
#define fallthrough
117117
#endif
118118
#ifndef _DEPRECATED
119119
#define _DEPRECATED(x) deprecated

lib/jhash.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -86,34 +86,34 @@ uint32_t jhash(const void *key, uint32_t length, uint32_t initval)
8686
switch (len) {
8787
case 11:
8888
c += ((uint32_t)k[10] << 24);
89-
/* fallthru */
89+
fallthrough;
9090
case 10:
9191
c += ((uint32_t)k[9] << 16);
92-
/* fallthru */
92+
fallthrough;
9393
case 9:
9494
c += ((uint32_t)k[8] << 8);
95-
/* fallthru */
95+
fallthrough;
9696
case 8:
9797
b += ((uint32_t)k[7] << 24);
98-
/* fallthru */
98+
fallthrough;
9999
case 7:
100100
b += ((uint32_t)k[6] << 16);
101-
/* fallthru */
101+
fallthrough;
102102
case 6:
103103
b += ((uint32_t)k[5] << 8);
104-
/* fallthru */
104+
fallthrough;
105105
case 5:
106106
b += k[4];
107-
/* fallthru */
107+
fallthrough;
108108
case 4:
109109
a += ((uint32_t)k[3] << 24);
110-
/* fallthru */
110+
fallthrough;
111111
case 3:
112112
a += ((uint32_t)k[2] << 16);
113-
/* fallthru */
113+
fallthrough;
114114
case 2:
115115
a += ((uint32_t)k[1] << 8);
116-
/* fallthru */
116+
fallthrough;
117117
case 1:
118118
a += k[0];
119119
}
@@ -148,7 +148,7 @@ uint32_t jhash2(const uint32_t *k, uint32_t length, uint32_t initval)
148148
switch (len) {
149149
case 2:
150150
b += k[1];
151-
/* fallthru */
151+
fallthrough;
152152
case 1:
153153
a += k[0];
154154
}

lib/libfrr.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
218218
break;
219219
case '6':
220220
path++;
221-
/* fallthrough */
221+
af = AF_INET6;
222+
break;
222223
default:
223224
af = AF_INET6;
224225
break;

lib/nexthop.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int _nexthop_cmp_no_labels(const struct nexthop *next1,
173173
ret = _nexthop_gateway_cmp(next1, next2);
174174
if (ret != 0)
175175
return ret;
176-
/* Intentional Fall-Through */
176+
fallthrough;
177177
case NEXTHOP_TYPE_IFINDEX:
178178
if (next1->ifindex < next2->ifindex)
179179
return -1;
@@ -295,7 +295,7 @@ int nexthop_cmp_basic(const struct nexthop *nh1,
295295
ret = nexthop_g_addr_cmp(nh1->type, &nh1->gate, &nh2->gate);
296296
if (ret != 0)
297297
return ret;
298-
/* Intentional Fall-Through */
298+
fallthrough;
299299
case NEXTHOP_TYPE_IFINDEX:
300300
if (nh1->ifindex < nh2->ifindex)
301301
return -1;

lib/nexthop_group.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static struct nexthop *nhg_nh_find(const struct nexthop_group *nhg,
180180
&nexthop->gate, &nh->gate);
181181
if (ret != 0)
182182
continue;
183-
/* Intentional Fall-Through */
183+
fallthrough;
184184
case NEXTHOP_TYPE_IFINDEX:
185185
if (nexthop->ifindex != nh->ifindex)
186186
continue;

0 commit comments

Comments
 (0)