From 74e2e548960b6ca6dd3e599cd47727c7b7023ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 8 Dec 2021 10:06:49 +0100 Subject: [PATCH 1/3] test-dhcp-option: rename variable to avoid global/local name conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeQL was complaining that the local variable obscurs the global one. It is indeed a bit confusing when reading this… Let's rename the variable to avoid confusing the reader. --- src/libsystemd-network/test-dhcp-option.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libsystemd-network/test-dhcp-option.c b/src/libsystemd-network/test-dhcp-option.c index c4a0d4ccb2..2c82ac982d 100644 --- a/src/libsystemd-network/test-dhcp-option.c +++ b/src/libsystemd-network/test-dhcp-option.c @@ -278,7 +278,7 @@ static void test_option_removal(struct option_desc *desc) { assert_se(dhcp_option_parse(message, sizeof(DHCPMessage) + desc->len, NULL, NULL, NULL) < 0); } -static uint8_t options[64] = { +static uint8_t the_options[64] = { 'A', 'B', 'C', 'D', 160, 2, 0x11, 0x12, 0, @@ -316,16 +316,16 @@ static void test_option_set(void) { offset = pos = 4; len = 11; - while (pos < len && options[pos] != SD_DHCP_OPTION_END) { + while (pos < len && the_options[pos] != SD_DHCP_OPTION_END) { assert_se(dhcp_option_append(result, len, &offset, DHCP_OVERLOAD_SNAME, - options[pos], - options[pos + 1], - &options[pos + 2]) >= 0); + the_options[pos], + the_options[pos + 1], + &the_options[pos + 2]) >= 0); - if (options[pos] == SD_DHCP_OPTION_PAD) + if (the_options[pos] == SD_DHCP_OPTION_PAD) pos++; else - pos += 2 + options[pos + 1]; + pos += 2 + the_options[pos + 1]; if (pos < len) assert_se(offset == pos); @@ -334,8 +334,8 @@ static void test_option_set(void) { for (i = 0; i < 9; i++) { if (verbose) printf("%2u: 0x%02x(0x%02x) (options)\n", i, result->options[i], - options[i]); - assert_se(result->options[i] == options[i]); + the_options[i]); + assert_se(result->options[i] == the_options[i]); } if (verbose) @@ -353,8 +353,8 @@ static void test_option_set(void) { for (i = 0; i < pos - 8; i++) { if (verbose) printf("%2u: 0x%02x(0x%02x) (sname)\n", i, result->sname[i], - options[i + 9]); - assert_se(result->sname[i] == options[i + 9]); + the_options[i + 9]); + assert_se(result->sname[i] == the_options[i + 9]); } if (verbose) From 1a735f9b22d474ef4f9826bb0465d3fd24293ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 8 Dec 2021 10:07:08 +0100 Subject: [PATCH 2/3] test-exec-util: rename variable to avoid global/local name conflict --- src/test/test-exec-util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/test-exec-util.c b/src/test/test-exec-util.c index 94ef6e8bbf..47a82eb969 100644 --- a/src/test/test-exec-util.c +++ b/src/test/test-exec-util.c @@ -236,7 +236,7 @@ static int gather_stdout_three(int fd, void *arg) { return 0; } -const gather_stdout_callback_t gather_stdout[] = { +const gather_stdout_callback_t gather_stdouts[] = { gather_stdout_one, gather_stdout_two, gather_stdout_three, @@ -277,7 +277,8 @@ TEST(stdout_gathering) { if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno)) return; - r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, gather_stdout, args, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS); + r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, gather_stdouts, args, NULL, NULL, + EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS); assert_se(r >= 0); log_info("got: %s", output); From 874e525de49d75253fa0c19d355e0e13a6c915a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 8 Dec 2021 10:09:30 +0100 Subject: [PATCH 3/3] test-dhcp-option: inline iterator variable declarations --- src/libsystemd-network/test-dhcp-option.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/libsystemd-network/test-dhcp-option.c b/src/libsystemd-network/test-dhcp-option.c index 2c82ac982d..800a6641e3 100644 --- a/src/libsystemd-network/test-dhcp-option.c +++ b/src/libsystemd-network/test-dhcp-option.c @@ -146,7 +146,6 @@ static int test_options_cb(uint8_t code, uint8_t len, const void *option, void * int *desclen = NULL, *descpos = NULL; uint8_t optcode = 0; uint8_t optlen = 0; - uint8_t i; assert_se((!desc && !code && !len) || desc); @@ -199,11 +198,11 @@ static int test_options_cb(uint8_t code, uint8_t len, const void *option, void * assert_se(code == optcode); assert_se(len == optlen); - for (i = 0; i < len; i++) { - + for (unsigned i = 0; i < len; i++) { if (verbose) - printf("0x%02x(0x%02x) ", ((uint8_t*) option)[i], - descoption[*descpos + 2 + i]); + printf("0x%02x(0x%02x) ", + ((uint8_t*) option)[i], + descoption[*descpos + 2 + i]); assert_se(((uint8_t*) option)[i] == descoption[*descpos + 2 + i]); } @@ -292,7 +291,6 @@ static uint8_t the_options[64] = { static void test_option_set(void) { _cleanup_free_ DHCPMessage *result = NULL; size_t offset = 0, len, pos; - unsigned i; result = malloc0(sizeof(DHCPMessage) + 11); assert_se(result); @@ -331,7 +329,7 @@ static void test_option_set(void) { assert_se(offset == pos); } - for (i = 0; i < 9; i++) { + for (unsigned i = 0; i < 9; i++) { if (verbose) printf("%2u: 0x%02x(0x%02x) (options)\n", i, result->options[i], the_options[i]); @@ -350,7 +348,7 @@ static void test_option_set(void) { assert_se(result->options[10] == SD_DHCP_OPTION_PAD); - for (i = 0; i < pos - 8; i++) { + for (unsigned i = 0; i < pos - 8; i++) { if (verbose) printf("%2u: 0x%02x(0x%02x) (sname)\n", i, result->sname[i], the_options[i + 9]); @@ -362,19 +360,17 @@ static void test_option_set(void) { } int main(int argc, char *argv[]) { - unsigned i; - test_invalid_buffer_length(); test_message_init(); test_options(NULL); - for (i = 0; i < ELEMENTSOF(option_tests); i++) + for (unsigned i = 0; i < ELEMENTSOF(option_tests); i++) test_options(&option_tests[i]); test_option_set(); - for (i = 0; i < ELEMENTSOF(option_tests); i++) { + for (unsigned i = 0; i < ELEMENTSOF(option_tests); i++) { struct option_desc *desc = &option_tests[i]; if (!desc->success || desc->snamelen > 0 || desc->filelen > 0) continue;