diff options
author | Igor Ryzhov <iryzhov@nfware.com> | 2023-10-10 23:15:32 +0200 |
---|---|---|
committer | Igor Ryzhov <iryzhov@nfware.com> | 2023-10-12 20:23:18 +0200 |
commit | 7d67b9ff28d09de58c632f80ef7d330e45e698f6 (patch) | |
tree | 16c8afc9dc80d70951f83d2f1182ace0edc7ee49 /lib | |
parent | Merge pull request #14559 from opensourcerouting/feature/update_dev_versions_... (diff) | |
download | frr-7d67b9ff28d09de58c632f80ef7d330e45e698f6.tar.xz frr-7d67b9ff28d09de58c632f80ef7d330e45e698f6.zip |
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 <iryzhov@nfware.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base64.c | 13 | ||||
-rw-r--r-- | lib/command_match.c | 4 | ||||
-rw-r--r-- | lib/compiler.h | 8 | ||||
-rw-r--r-- | lib/jhash.c | 22 | ||||
-rw-r--r-- | lib/libfrr.c | 3 | ||||
-rw-r--r-- | lib/nexthop.c | 4 | ||||
-rw-r--r-- | lib/nexthop_group.c | 2 | ||||
-rw-r--r-- | lib/printf/printf-pos.c | 20 | ||||
-rw-r--r-- | lib/printf/vfprintf.c | 12 | ||||
-rw-r--r-- | lib/routemap_northbound.c | 5 | ||||
-rw-r--r-- | lib/vty.c | 2 | ||||
-rw-r--r-- | lib/workqueue.c | 10 | ||||
-rw-r--r-- | lib/zclient.c | 2 | ||||
-rw-r--r-- | lib/zlog_5424.c | 2 |
14 files changed, 57 insertions, 52 deletions
diff --git a/lib/base64.c b/lib/base64.c index 1507b0252..ee2e838c0 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -9,6 +9,7 @@ #endif #include "base64.h" +#include "compiler.h" static const int CHARS_PER_LINE = 72; static const char *ENCODING = @@ -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; @@ -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; @@ -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; @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/lib/command_match.c b/lib/command_match.c index f740b7260..97e6aeb46 100644 --- a/lib/command_match.c +++ b/lib/command_match.c @@ -405,10 +405,10 @@ enum matcher_rv command_complete(struct graph *graph, vector vline, listnode_add(next, newstack); break; case partly_match: - trace_matcher("trivial_match\n"); + trace_matcher("partly_match\n"); if (exact_match_exists && !last_token) break; - /* fallthru */ + fallthrough; case exact_match: trace_matcher("exact_match\n"); if (last_token) { diff --git a/lib/compiler.h b/lib/compiler.h index ce6727685..0a54c02d2 100644 --- a/lib/compiler.h +++ b/lib/compiler.h @@ -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) @@ -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 @@ -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 diff --git a/lib/jhash.c b/lib/jhash.c index 0d561ef3a..4e02112e0 100644 --- a/lib/jhash.c +++ b/lib/jhash.c @@ -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]; } @@ -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]; } diff --git a/lib/libfrr.c b/lib/libfrr.c index 33237df5f..e80355f3b 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -218,7 +218,8 @@ bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len, break; case '6': path++; - /* fallthrough */ + af = AF_INET6; + break; default: af = AF_INET6; break; diff --git a/lib/nexthop.c b/lib/nexthop.c index 8df57e36a..4ddb53cd9 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -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; @@ -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; diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 25370eba4..c75ff7b4c 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -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; diff --git a/lib/printf/printf-pos.c b/lib/printf/printf-pos.c index ac775bea4..b2ba1a714 100644 --- a/lib/printf/printf-pos.c +++ b/lib/printf/printf-pos.c @@ -355,7 +355,7 @@ reswitch: switch (ch) { goto rflag; case 'C': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'c': error = addtype(&types, (flags & LONGINT) ? T_WINT : T_INT); @@ -364,7 +364,7 @@ reswitch: switch (ch) { break; case 'D': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'd': case 'i': if ((error = addsarg(&types, flags))) @@ -408,7 +408,7 @@ reswitch: switch (ch) { #endif case 'O': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'o': if ((error = adduarg(&types, flags))) goto error; @@ -419,7 +419,7 @@ reswitch: switch (ch) { break; case 'S': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 's': error = addtype(&types, (flags & LONGINT) ? TP_WCHAR : TP_CHAR); @@ -428,7 +428,7 @@ reswitch: switch (ch) { break; case 'U': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'u': case 'X': case 'x': @@ -549,7 +549,7 @@ reswitch: switch (ch) { goto rflag; case 'C': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'c': error = addtype(&types, (flags & LONGINT) ? T_WINT : T_INT); @@ -558,7 +558,7 @@ reswitch: switch (ch) { break; case 'D': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'd': case 'i': if ((error = addsarg(&types, flags))) @@ -602,7 +602,7 @@ reswitch: switch (ch) { #endif case 'O': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'o': if ((error = adduarg(&types, flags))) goto error; @@ -613,7 +613,7 @@ reswitch: switch (ch) { break; case 'S': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 's': error = addtype(&types, (flags & LONGINT) ? TP_WCHAR : TP_CHAR); @@ -622,7 +622,7 @@ reswitch: switch (ch) { break; case 'U': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'u': case 'X': case 'x': diff --git a/lib/printf/vfprintf.c b/lib/printf/vfprintf.c index 78f8be05c..2083642d5 100644 --- a/lib/printf/vfprintf.c +++ b/lib/printf/vfprintf.c @@ -340,7 +340,7 @@ reswitch: switch (ch) { if (width >= 0) goto rflag; width = -width; - /* FALLTHROUGH */ + fallthrough; case '-': flags |= LADJUST; goto rflag; @@ -434,7 +434,7 @@ reswitch: switch (ch) { break; case 'C': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'c': #ifdef WCHAR_SUPPORT if (flags & LONGINT) { @@ -460,7 +460,7 @@ reswitch: switch (ch) { break; case 'D': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'd': case 'i': if (flags & INTMAX_SIZE) @@ -551,7 +551,7 @@ reswitch: switch (ch) { break; case 'O': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'o': if (flags & INTMAX_SIZE) ujval = UJARG(); @@ -595,7 +595,7 @@ reswitch: switch (ch) { goto nosign; case 'S': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 's': #ifdef WCHAR_SUPPORT if (flags & LONGINT) { @@ -621,7 +621,7 @@ reswitch: switch (ch) { break; case 'U': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'u': if (flags & INTMAX_SIZE) ujval = UJARG(); diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c index 5767e0aac..9e25d2beb 100644 --- a/lib/routemap_northbound.c +++ b/lib/routemap_northbound.c @@ -364,7 +364,6 @@ lib_route_map_entry_exit_policy_modify(struct nb_cb_modify_args *args) case 0: /* permit-or-deny */ break; case 1: /* next */ - /* FALLTHROUGH */ case 2: /* goto */ rm_action = yang_dnode_get_enum(args->dnode, "../action"); @@ -885,7 +884,7 @@ static int lib_route_map_entry_set_action_ipv4_address_modify( yang_dnode_get_ipv4(&ia, args->dnode, NULL); if (ia.s_addr == INADDR_ANY || !ipv4_unicast_valid(&ia)) return NB_ERR_VALIDATION; - /* FALLTHROUGH */ + return NB_OK; case NB_EV_PREPARE: case NB_EV_ABORT: return NB_OK; @@ -944,7 +943,7 @@ static int lib_route_map_entry_set_action_ipv6_address_modify( yang_dnode_get_ipv6(&i6a, args->dnode, NULL); if (!IN6_IS_ADDR_LINKLOCAL(&i6a)) return NB_ERR_VALIDATION; - /* FALLTHROUGH */ + return NB_OK; case NB_EV_PREPARE: case NB_EV_ABORT: return NB_OK; @@ -1565,7 +1565,7 @@ static void vty_read(struct event *thread) break; case '\r': vty->escape = VTY_CR; - /* fallthru */ + fallthrough; case '\n': vty_out(vty, "\n"); buffer_flush_available(vty->obuf, vty->wfd); diff --git a/lib/workqueue.c b/lib/workqueue.c index fa5d58536..2281c4c36 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -271,9 +271,10 @@ void work_queue_run(struct event *thread) switch (ret) { case WQ_QUEUE_BLOCKED: { /* decrement item->ran again, cause this isn't an item - * specific error, and fall through to WQ_RETRY_LATER + * specific error, and retry later */ item->ran--; + goto stats; } case WQ_RETRY_LATER: { goto stats; @@ -296,9 +297,10 @@ void work_queue_run(struct event *thread) break; } case WQ_RETRY_NOW: - /* a RETRY_NOW that gets here has exceeded max_tries, same as - * ERROR */ - /* fallthru */ + /* a RETRY_NOW that gets here has exceeded max_tries, same + * as ERROR + */ + fallthrough; case WQ_SUCCESS: default: { work_queue_item_remove(wq, item); diff --git a/lib/zclient.c b/lib/zclient.c index f8f9cf7ab..47d6c5fba 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -891,7 +891,7 @@ static int zapi_nexthop_cmp_no_labels(const struct zapi_nexthop *next1, &next2->gate); if (ret != 0) return ret; - /* Intentional Fall-Through */ + fallthrough; case NEXTHOP_TYPE_IFINDEX: if (next1->ifindex < next2->ifindex) return -1; diff --git a/lib/zlog_5424.c b/lib/zlog_5424.c index 9bc1c819a..3049e4a84 100644 --- a/lib/zlog_5424.c +++ b/lib/zlog_5424.c @@ -913,7 +913,7 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type) } flags = O_NONBLOCK; - /* fallthru */ + fallthrough; case ZLOG_5424_DST_FILE: if (!zcf->filename) |