From: Álvaro Fernández Rojas Date: Fri, 14 Nov 2025 06:57:21 +0000 (+0100) Subject: src: consolidate and improve fallthrough X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=8a8bb3c1a673e567c438472339084943df72540b;p=project%2Fodhcpd.git src: consolidate and improve fallthrough - Enable fallthrough warnings. - Use fallthrough attribute instead of comments. - Drop unneeded fallthroughs (no code between two case statements). Signed-off-by: Álvaro Fernández Rojas Link: https://github.com/openwrt/odhcpd/pull/307 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 34d6ea4..703d6b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ target_compile_options(${PROJECT_NAME} PRIVATE -Werror=implicit-function-declara target_compile_options(${PROJECT_NAME} PRIVATE -Wformat) target_compile_options(${PROJECT_NAME} PRIVATE -Werror=format-security) target_compile_options(${PROJECT_NAME} PRIVATE -Werror=format-nonliteral) +target_compile_options(${PROJECT_NAME} PRIVATE -Wimplicit-fallthrough=5) target_compile_options(${PROJECT_NAME} PRIVATE -Wno-unused-parameter) target_compile_options(${PROJECT_NAME} PRIVATE -Wmissing-declarations) diff --git a/src/config.c b/src/config.c index ff93da7..27ab531 100644 --- a/src/config.c +++ b/src/config.c @@ -1011,14 +1011,12 @@ static int parse_dnr_str(char *str, struct interface *iface) break; case DNR_SVC_NO_DEFAULT_ALPN: - /* fall through */ - case DNR_SVC_OHTTP: if (strlen(svc_val_str) > 0) { error("Invalid value '%s' for SvcParam 'port'", svc_val_str); goto err; } - /* fall through */ + _fallthrough; case DNR_SVC_DOHPATH: /* plain string */ @@ -1042,8 +1040,6 @@ static int parse_dnr_str(char *str, struct interface *iface) goto err; case DNR_SVC_IPV4HINT: - /* fall through */ - case DNR_SVC_IPV6HINT: error("SvcParam '%s' is not allowed", svc_param_key_names[svc_key]); goto err; diff --git a/src/dhcpv4.c b/src/dhcpv4.c index d1811ec..2229197 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -578,8 +578,6 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re break; case DHCPV4_MSG_DISCOVER: - _fallthrough; - case DHCPV4_MSG_REQUEST: if (!lease && iface->no_dynamic_dhcp && !lease_cfg) return NULL; @@ -1013,7 +1011,6 @@ void dhcpv4_handle_msg(void *src_addr, void *data, size_t len, case DHCPV4_MSG_INFORM: break; case DHCPV4_MSG_DECLINE: - _fallthrough; case DHCPV4_MSG_RELEASE: dhcpv4_lease(iface, req_msg, req->chaddr, req_clientid, req_clientid_len, req_addr, &req_leasetime, @@ -1021,7 +1018,6 @@ void dhcpv4_handle_msg(void *src_addr, void *data, size_t len, &reply_incl_fr, &fr_serverid); return; case DHCPV4_MSG_DISCOVER: - _fallthrough; case DHCPV4_MSG_REQUEST: lease = dhcpv4_lease(iface, req_msg, req->chaddr, req_clientid, req_clientid_len, req_addr, &req_leasetime, diff --git a/src/ndp.c b/src/ndp.c index 58ed5f4..6924602 100644 --- a/src/ndp.c +++ b/src/ndp.c @@ -244,13 +244,13 @@ static void ndp_netevent_cb(unsigned long event, struct netevent_handler_info *i case NETEV_ADDR6_DEL: add = false; netlink_dump_neigh_table(false); - /* fall through */ + _fallthrough; case NETEV_ADDR6_ADD: setup_addr_for_relaying(&info->addr.in6, iface, add); break; case NETEV_NEIGH6_DEL: add = false; - /* fall through */ + _fallthrough; case NETEV_NEIGH6_ADD: if (info->neigh.flags & NTF_PROXY) { if (add) { diff --git a/src/netlink.c b/src/netlink.c index c612884..9ef1a28 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -452,21 +452,21 @@ static int cb_rtnl_valid(struct nl_msg *msg, _unused void *arg) case RTM_NEWROUTE: add = true; - /* fall through */ + _fallthrough; case RTM_DELROUTE: ret = handle_rtm_route(hdr, add); break; case RTM_NEWADDR: add = true; - /* fall through */ + _fallthrough; case RTM_DELADDR: ret = handle_rtm_addr(hdr, add); break; case RTM_NEWNEIGH: add = true; - /* fall through */ + _fallthrough; case RTM_DELNEIGH: ret = handle_rtm_neigh(hdr, add); break;