From 98dfd156f399b6b2039917d858e31e5e96c3a807 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Fri, 28 Nov 2025 08:42:29 +0100 Subject: [PATCH] src: fix shadowed local variables MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix shadowed local variables and enable warning to prevent more shadowed variables in the future. Signed-off-by: Álvaro Fernández Rojas --- CMakeLists.txt | 2 ++ src/ra.c | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebbe69b..57f5d2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,10 @@ 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-shadow=compatible-local) target_compile_options(${PROJECT_NAME} PRIVATE -Wno-unused-parameter) target_compile_options(${PROJECT_NAME} PRIVATE -Wmissing-declarations) +target_compile_options(${PROJECT_NAME} PRIVATE -Wshadow=local) # Libraries diff --git a/src/ra.c b/src/ra.c index 0c83e54..b980858 100644 --- a/src/ra.c +++ b/src/ra.c @@ -537,18 +537,18 @@ bool ra_process(void) } } else if (opt->type == ND_OPT_DNSSL && opt->len > 1) { uint32_t *valid = (uint32_t*)&opt->data[2]; - uint8_t *buf = &opt->data[6]; - uint8_t *end = &buf[(opt->len - 1) * 8]; + uint8_t *ds_buf = &opt->data[6]; + uint8_t *end = &ds_buf[(opt->len - 1) * 8]; entry->router = from.sin6_addr; entry->valid = ntohl(*valid); - while (buf < end) { - int len = dn_expand(buf, end, buf, (char*)entry->auxtarget, 256); - if (len < 1) + while (ds_buf < end) { + int ds_len = dn_expand(ds_buf, end, ds_buf, (char*)entry->auxtarget, 256); + if (ds_len < 1) break; - buf = &buf[len]; + ds_buf = &ds_buf[ds_len]; entry->auxlen = strlen((char*)entry->auxtarget); if (entry->auxlen == 0) @@ -564,7 +564,7 @@ bool ra_process(void) continue; struct icmpv6_opt_captive_portal *capt_port = (struct icmpv6_opt_captive_portal*)opt; - uint8_t *buf = &capt_port->data[0]; + uint8_t *cp_buf = &capt_port->data[0]; size_t ref_len = sizeof(URN_IETF_CAPT_PORT_UNRESTR) - 1; /* RFC8910 §2: @@ -572,7 +572,7 @@ bool ra_process(void) * condition by using this option with the IANA-assigned URI for * this purpose. Clients observing the URI value ... may forego * time-consuming forms of captive portal detection. */ - if (memcmp(buf, URN_IETF_CAPT_PORT_UNRESTR, ref_len)) { + if (memcmp(cp_buf, URN_IETF_CAPT_PORT_UNRESTR, ref_len)) { /* URI are not guaranteed to be \0 terminated if data is unpadded */ size_t uri_len = (capt_port->len * 8) - 2; /* Allocate new buffer including room for '\0' */ @@ -580,7 +580,7 @@ bool ra_process(void) if (!copy) continue; - memcpy(copy, buf, uri_len); + memcpy(copy, cp_buf, uri_len); copy[uri_len] = '\0'; odhcp6c_clear_state(STATE_CAPT_PORT_RA); odhcp6c_add_state(STATE_CAPT_PORT_RA, copy, uri_len); -- 2.30.2