src: consolidate and improve fallthrough
authorÁlvaro Fernández Rojas <[email protected]>
Fri, 14 Nov 2025 06:57:21 +0000 (07:57 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Mon, 17 Nov 2025 07:24:34 +0000 (08:24 +0100)
- 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 <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/307
CMakeLists.txt
src/config.c
src/dhcpv4.c
src/ndp.c
src/netlink.c

index 34d6ea4a2cc767c40605a4cf346d3c007e7fa60c..703d6b1f7583f41764c1fe385941d11d1c83b8ee 100644 (file)
@@ -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)
 
index ff93da71b6fd321bf08d4dc61133e8beb4ae1c74..27ab531c775a7333deed26aea7e87910fcf947de 100644 (file)
@@ -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;
index d1811ec5ed037d7bec95c8cc2f55c555eeefa9ad..22291979422530e47c783dd19a13c20c06f8f4d2 100644 (file)
@@ -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,
index 58ed5f4c548df2a7ab6319635d46f01345fef3fc..6924602bdfc462c97241f551d4a0a6f1c206a656 100644 (file)
--- 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) {
index c612884f604b731788ccf218ee2920f1c53178cb..9ef1a2824554e02a9ad22f38b2510de5f2c314de 100644 (file)
@@ -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;