diff --git a/lib/command.c b/lib/command.c index 6d023142ab..4e8194bbc6 100644 --- a/lib/command.c +++ b/lib/command.c @@ -949,7 +949,8 @@ static int cmd_execute_command_real(vector vline, enum cmd_filter_type filter, return CMD_ERR_INCOMPLETE; case MATCHER_AMBIGUOUS: return CMD_ERR_AMBIGUOUS; - default: + case MATCHER_NO_MATCH: + case MATCHER_OK: return CMD_ERR_NO_MATCH; } } diff --git a/lib/command_graph.c b/lib/command_graph.c index e940685250..766d7e9371 100644 --- a/lib/command_graph.c +++ b/lib/command_graph.c @@ -267,9 +267,22 @@ static bool cmd_nodes_equal(struct graph_node *ga, struct graph_node *gb) return false; return cmd_subgraph_equal(ga, gb, a->forkjoin); - default: + case VARIABLE_TKN: + case IPV4_TKN: + case IPV4_PREFIX_TKN: + case IPV6_PREFIX_TKN: + case IPV6_TKN: + case MAC_TKN: + case MAC_PREFIX_TKN: + case JOIN_TKN: + case START_TKN: + case END_TKN: + case NEG_ONLY_TKN: + case WORD_TKN: return true; } + + assert(!"Reached end of function we should never hit"); } static void cmd_fork_bump_attr(struct graph_node *gn, struct graph_node *join, @@ -477,7 +490,7 @@ void cmd_graph_node_print_cb(struct graph_node *gn, struct buffer *buf) char nbuf[512]; struct cmd_token *tok = gn->data; - const char *color; + const char *color = NULL; if (wasend) { wasend = false; @@ -526,10 +539,23 @@ void cmd_graph_node_print_cb(struct graph_node *gn, struct buffer *buf) case WORD_TKN: color = "#ffffff"; break; - default: + case RANGE_TKN: + case IPV4_TKN: + case IPV4_PREFIX_TKN: + case IPV6_TKN: + case IPV6_PREFIX_TKN: + case MAC_TKN: + case MAC_PREFIX_TKN: + case END_TKN: + case VARIABLE_TKN: color = "#ffffff"; break; } + + /* + * Some compilers have the mistaken belief that we can + * get here without initializing color. + */ snprintf(nbuf, sizeof(nbuf), ">, style = filled, fillcolor = \"%s\" ];\n", color); buffer_putstr(buf, nbuf); diff --git a/lib/command_match.c b/lib/command_match.c index ce2dbc9528..6c1d05d926 100644 --- a/lib/command_match.c +++ b/lib/command_match.c @@ -437,7 +437,7 @@ enum matcher_rv command_complete(struct graph *graph, vector vline, add_nexthops(next, gstack[0], gstack, idx + 1, neg); break; - default: + case no_match: trace_matcher("no_match\n"); break; } @@ -544,9 +544,22 @@ static enum match_type min_match_level(enum cmd_token_type type) // allowing words to partly match enables command abbreviation case WORD_TKN: return partly_match; - default: + case RANGE_TKN: + case IPV4_TKN: + case IPV4_PREFIX_TKN: + case IPV6_TKN: + case IPV6_PREFIX_TKN: + case MAC_TKN: + case MAC_PREFIX_TKN: + case FORK_TKN: + case JOIN_TKN: + case END_TKN: + case NEG_ONLY_TKN: + case VARIABLE_TKN: return exact_match; } + + assert(!"Reached end of function we should never hit"); } /** @@ -572,9 +585,15 @@ static int score_precedence(enum cmd_token_type type) return 3; case VARIABLE_TKN: return 4; - default: + case JOIN_TKN: + case START_TKN: + case END_TKN: + case NEG_ONLY_TKN: + case SPECIAL_TKN: return 10; } + + assert(!"Reached end of function we should never hit"); } /** @@ -695,9 +714,14 @@ static enum match_type match_token(struct cmd_token *token, char *input_token) case MAC_PREFIX_TKN: return match_mac(input_token, true); case END_TKN: - default: + case FORK_TKN: + case JOIN_TKN: + case START_TKN: + case NEG_ONLY_TKN: return no_match; } + + assert(!"Reached end of function we should never hit"); } #define IPV4_ADDR_STR "0123456789." diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c index 8fa47c053b..a62178ba0a 100644 --- a/lib/grammar_sandbox.c +++ b/lib/grammar_sandbox.c @@ -195,7 +195,7 @@ DEFUN (grammar_test_match, case MATCHER_AMBIGUOUS: vty_out(vty, "%% Ambiguous command\n"); break; - default: + case MATCHER_OK: vty_out(vty, "%% Unknown error\n"); break; } diff --git a/lib/iana_afi.h b/lib/iana_afi.h index 56e8a24b86..41e83d45c8 100644 --- a/lib/iana_afi.h +++ b/lib/iana_afi.h @@ -61,9 +61,11 @@ static inline afi_t afi_iana2int(iana_afi_t afi) return AFI_IP6; case IANA_AFI_L2VPN: return AFI_L2VPN; - default: + case IANA_AFI_RESERVED: return AFI_MAX; } + + return AFI_MAX; } static inline iana_afi_t afi_int2iana(afi_t afi) @@ -75,9 +77,12 @@ static inline iana_afi_t afi_int2iana(afi_t afi) return IANA_AFI_IPV6; case AFI_L2VPN: return IANA_AFI_L2VPN; - default: + case AFI_UNSPEC: + case AFI_MAX: return IANA_AFI_RESERVED; } + + return IANA_AFI_RESERVED; } static inline const char *iana_afi2str(iana_afi_t afi) @@ -102,9 +107,11 @@ static inline safi_t safi_iana2int(iana_safi_t safi) return SAFI_LABELED_UNICAST; case IANA_SAFI_FLOWSPEC: return SAFI_FLOWSPEC; - default: + case IANA_SAFI_RESERVED: return SAFI_MAX; } + + return SAFI_MAX; } static inline iana_safi_t safi_int2iana(safi_t safi) @@ -124,9 +131,12 @@ static inline iana_safi_t safi_int2iana(safi_t safi) return IANA_SAFI_LABELED_UNICAST; case SAFI_FLOWSPEC: return IANA_SAFI_FLOWSPEC; - default: + case SAFI_UNSPEC: + case SAFI_MAX: return IANA_SAFI_RESERVED; } + + return IANA_SAFI_RESERVED; } static inline const char *iana_safi2str(iana_safi_t safi) diff --git a/lib/ipaddr.h b/lib/ipaddr.h index 43b3028200..4934a83b4c 100644 --- a/lib/ipaddr.h +++ b/lib/ipaddr.h @@ -70,9 +70,11 @@ static inline int ipaddr_family(const struct ipaddr *ip) return AF_INET; case IPADDR_V6: return AF_INET6; - default: + case IPADDR_NONE: return AF_UNSPEC; } + + assert(!"Reached end of function where we should never hit"); } static inline int str2ipaddr(const char *str, struct ipaddr *ip) @@ -158,9 +160,11 @@ static inline int ipaddr_cmp(const struct ipaddr *a, const struct ipaddr *b) case IPADDR_V6: return memcmp((void *)&a->ipaddr_v6, (void *)&b->ipaddr_v6, sizeof(a->ipaddr_v6)); - default: + case IPADDR_NONE: return 0; } + + assert(!"Reached end of function we should never hit"); } static inline bool ipaddr_is_zero(const struct ipaddr *ip) diff --git a/lib/link_state.c b/lib/link_state.c index 1b79c79216..c59cd040c8 100644 --- a/lib/link_state.c +++ b/lib/link_state.c @@ -443,7 +443,7 @@ struct ls_vertex *ls_vertex_add(struct ls_ted *ted, struct ls_node *node) case ISIS_L2: key = sysid_to_key(node->adv.id.iso.sys_id); break; - default: + case UNKNOWN: key = 0; break; } @@ -565,7 +565,7 @@ struct ls_vertex *ls_find_vertex_by_id(struct ls_ted *ted, case ISIS_L2: vertex.key = sysid_to_key(nid.id.iso.sys_id); break; - default: + case UNKNOWN: return NULL; } @@ -1649,7 +1649,8 @@ struct ls_message *ls_vertex2msg(struct ls_message *msg, case SYNC: msg->event = LS_MSG_EVENT_SYNC; break; - default: + case UNSET: + case ORPHAN: msg->event = LS_MSG_EVENT_UNDEF; break; } @@ -1681,7 +1682,8 @@ struct ls_message *ls_edge2msg(struct ls_message *msg, struct ls_edge *edge) case SYNC: msg->event = LS_MSG_EVENT_SYNC; break; - default: + case UNSET: + case ORPHAN: msg->event = LS_MSG_EVENT_UNDEF; break; } @@ -1717,7 +1719,8 @@ struct ls_message *ls_subnet2msg(struct ls_message *msg, case SYNC: msg->event = LS_MSG_EVENT_SYNC; break; - default: + case UNSET: + case ORPHAN: msg->event = LS_MSG_EVENT_UNDEF; break; } diff --git a/lib/prefix.c b/lib/prefix.c index 1d098f78c5..9d6dc73572 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -148,11 +148,11 @@ const char *afi2str(afi_t afi) case AFI_L2VPN: return "l2vpn"; case AFI_MAX: + case AFI_UNSPEC: return "bad-value"; - default: - break; } - return NULL; + + assert(!"Reached end of function we should never reach"); } const char *safi2str(safi_t safi) @@ -172,9 +172,12 @@ const char *safi2str(safi_t safi) return "labeled-unicast"; case SAFI_FLOWSPEC: return "flowspec"; - default: + case SAFI_UNSPEC: + case SAFI_MAX: return "unknown"; } + + assert(!"Reached end of function we should never reach"); } /* If n includes p prefix then return 1 else return 0. */ @@ -1507,7 +1510,7 @@ static ssize_t printfrr_ia(struct fbuf *buf, struct printfrr_eargs *ea, return bputch(buf, '*'); break; - default: + case IPADDR_NONE: break; } } diff --git a/lib/routemap.c b/lib/routemap.c index 44d7185567..f56e6a6122 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -1754,7 +1754,8 @@ route_map_apply_match(struct route_map_rule_list *match_list, ret = RMAP_MATCH; break; - default: + case RMAP_OKAY: + case RMAP_ERROR: break; } diff --git a/lib/stream.c b/lib/stream.c index 2de3abdf45..0756f90274 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -635,7 +635,7 @@ uint32_t stream_get_ipv4(struct stream *s) bool stream_get_ipaddr(struct stream *s, struct ipaddr *ip) { - uint16_t ipa_len; + uint16_t ipa_len = 0; STREAM_VERIFY_SANE(s); @@ -654,7 +654,7 @@ bool stream_get_ipaddr(struct stream *s, struct ipaddr *ip) case IPADDR_V6: ipa_len = IPV6_MAX_BYTELEN; break; - default: + case IPADDR_NONE: flog_err(EC_LIB_DEVELOPMENT, "%s: unknown ip address-family: %u", __func__, ip->ipa_type); @@ -947,7 +947,7 @@ bool stream_put_ipaddr(struct stream *s, struct ipaddr *ip) case IPADDR_V6: stream_write(s, (uint8_t *)&ip->ipaddr_v6, 16); break; - default: + case IPADDR_NONE: flog_err(EC_LIB_DEVELOPMENT, "%s: unknown ip address-family: %u", __func__, ip->ipa_type); diff --git a/lib/vrf.c b/lib/vrf.c index 7d2ca6f1e1..baf25dfa0e 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -610,7 +610,7 @@ int vrf_configure_backend(enum vrf_backend_type backend) case VRF_BACKEND_NETNS: case VRF_BACKEND_VRF_LITE: break; - default: + case VRF_BACKEND_MAX: return -1; } diff --git a/lib/vty.c b/lib/vty.c index 76d907408c..d53e07fe42 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -2714,7 +2714,11 @@ static void vty_event_serv(enum vty_event event, struct vty_serv *vty_serv) vty_serv->sock, &vty_serv->t_accept); break; #endif /* VTYSH */ - default: + case VTY_READ: + case VTY_WRITE: + case VTY_TIMEOUT_RESET: + case VTYSH_READ: + case VTYSH_WRITE: assert(!"vty_event_serv() called incorrectly"); } } @@ -2753,7 +2757,8 @@ static void vty_event(enum vty_event event, struct vty *vty) thread_add_timer(vty_master, vty_timeout, vty, vty->v_timeout, &vty->t_timeout); break; - default: + case VTY_SERV: + case VTYSH_SERV: assert(!"vty_event() called incorrectly"); } } diff --git a/lib/zclient.c b/lib/zclient.c index 07c7e5aea8..d748bef335 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1682,7 +1682,8 @@ int zapi_tc_class_encode(uint8_t cmd, struct stream *s, struct tc_class *class) stream_putq(s, class->u.htb.rate); stream_putq(s, class->u.htb.ceil); break; - default: + case TC_QDISC_UNSPEC: + case TC_QDISC_NOQUEUE: /* not implemented */ break; } @@ -1730,7 +1731,10 @@ int zapi_tc_filter_encode(uint8_t cmd, struct stream *s, } stream_putl(s, filter->u.flower.classid); break; - default: + case TC_FILTER_UNSPEC: + case TC_FILTER_BPF: + case TC_FILTER_FLOW: + case TC_FILTER_U32: /* not implemented */ break; } diff --git a/lib/zlog_5424_cli.c b/lib/zlog_5424_cli.c index 5eebda9deb..be0988e0b3 100644 --- a/lib/zlog_5424_cli.c +++ b/lib/zlog_5424_cli.c @@ -877,7 +877,8 @@ static int log_5424_show(struct vty *vty) } break; - default: + case ZLOG_FMT_3164: + case ZLOG_FMT_LOCAL: vty_out(vty, " structured data is not supported by the selected format\n"); break;