From f71e869b976824e52f5a30e52e08bf6afde6e447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20van=20Dorst?= Date: Sat, 18 Apr 2026 00:02:01 +0200 Subject: [PATCH] parse_ingress() make use of cmd_words_len, refactor small parts --- cmd_parser.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd_parser.c b/cmd_parser.c index bbcfa77..acae573 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -476,7 +476,7 @@ bool vlan_ingress_mode_parse(char c, vlan_ingress_mode_t *mode) void parse_ingress(void) { - if (cmd_words_b[1] <= 0) { + if (cmd_words_len < 2) { goto err; } __xdata uint8_t log_port = 0; @@ -494,24 +494,25 @@ void parse_ingress(void) } return; } else { - for(uint8_t w = 1; cmd_words_b[w] > 0; w++) { - if (!isnumber(cmd_buffer[cmd_words_b[w]])) { + for(uint8_t w = 1; w < cmd_words_len; w++) { + uint8_t p = cmd_buffer[cmd_words_b[w]]; + if (!isnumber(p)) { continue; } - if (cmd_buffer[cmd_words_b[w]] - '1' > 9) { - print_string("Invalid physical port number: "); write_char(cmd_buffer[cmd_words_b[w]]); write_char('\n'); + if (p - '1' > 9) { + print_string("Invalid physical port number: "); write_char(p); write_char('\n'); continue; } - log_port = machine.phys_to_log_port[cmd_buffer[cmd_words_b[w]] - '1']; + log_port = machine.phys_to_log_port[p - '1']; if (!vlan_ingress_mode_parse(cmd_buffer[cmd_words_b[w] + 1], &mode)) { - print_string("Invalid ingress mode for port "); write_char(cmd_buffer[cmd_words_b[w]]); print_string(" in ingress command\n"); + print_string("Invalid ingress mode for port "); write_char(p); print_string(" in ingress command\n"); goto err; } if (!port_ingress_filter(log_port, mode)) { - print_string("Error setting ingress filter for port "); write_char(cmd_buffer[cmd_words_b[w]]); write_char('\n'); + print_string("Error setting ingress filter for port "); write_char(p); write_char('\n'); return; } - print_string("Port "); write_char(cmd_buffer[cmd_words_b[w]]); + print_string("Port "); write_char(p); print_string(" ingress filter set to: "); print_port_ingress_filter_mode(mode); write_char('\n'); }