From 38a31eb29a48da6c219cbbe49df30e36dba1d5db Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Fri, 14 Nov 2025 08:19:17 +0100 Subject: [PATCH] src: add fallthrough attribute MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Enable fallthrough warnings. - Use fallthrough attribute instead of comments. Signed-off-by: Álvaro Fernández Rojas Link: https://github.com/openwrt/odhcp6c/pull/120 --- CMakeLists.txt | 1 + src/dhcpv6.c | 6 +++--- src/odhcp6c.h | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9067819..ebbe69b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,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/dhcpv6.c b/src/dhcpv6.c index 7bcaee0..7f73699 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -1144,11 +1144,11 @@ static int dhcpv6_handle_reconfigure(enum dhcpv6_msg orig, const int rc, case DHCPV6_MSG_REBIND: if (t2 != UINT32_MAX) t2 = 0; - // Fall through + _o_fallthrough; case DHCPV6_MSG_RENEW: if (t1 != UINT32_MAX) t1 = 0; - // Fall through + _o_fallthrough; case DHCPV6_MSG_INFO_REQ: msg = odata[0]; syslog(LOG_NOTICE, "Need to respond with %s in reply to %s", @@ -2146,7 +2146,7 @@ int dhcpv6_send_request(enum dhcpv6_msg type) default: syslog(LOG_NOTICE, "Send %s message (elapsed %"PRIu64"ms, rc %d)", retx->name, elapsed, retx->rc); - // Fall through + _o_fallthrough; case DHCPV6_MSG_SOLICIT: case DHCPV6_MSG_INFO_REQ: dhcpv6_send(type, retx->tr_id, elapsed / 10); diff --git a/src/odhcp6c.h b/src/odhcp6c.h index 02578cc..42c645d 100644 --- a/src/odhcp6c.h +++ b/src/odhcp6c.h @@ -24,6 +24,10 @@ #define _o_aligned(n) __attribute__((aligned(n))) #endif /* _o_aligned */ +#ifndef _o_fallthrough +#define _o_fallthrough __attribute__((__fallthrough__)) +#endif /* _o_fallthrough */ + #ifndef _o_packed #define _o_packed __attribute__((packed)) #endif /* _o_packed */ -- 2.30.2