This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 198b89a81d80168beb4941a70e4fff2834183b4b Author: wangjianyu3 <[email protected]> AuthorDate: Mon Aug 10 16:20:35 2026 +0800 nshlib/ifconfig: drop the redundant "argc > 2" check cmd_ifconfig() returns early for argc <= 2, so by the time the argument loop is reached argc > 2 always holds. Remove the dead condition and unindent the loop. No functional change. Assisted-by: GitHubCopilot:claude-opus-5 Signed-off-by: wangjianyu3 <[email protected]> --- nshlib/nsh_netcmds.c | 225 +++++++++++++++++++++++++-------------------------- 1 file changed, 111 insertions(+), 114 deletions(-) diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index b7f92f5ca..defcb717f 100644 --- a/nshlib/nsh_netcmds.c +++ b/nshlib/nsh_netcmds.c @@ -623,163 +623,160 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) * ifconfig ifname [ip_address] [named options] */ - if (argc > 2) + for (i = 1; i < argc; i++) { - for (i = 1; i < argc; i++) + if (i == 1) { - if (i == 1) + ifname = argv[i]; + missingarg = false; + } + else + { + tmp = argv[i]; + + if (!strcmp(tmp, "dr") || !strcmp(tmp, "gw") || + !strcmp(tmp, "gateway")) { - ifname = argv[i]; - missingarg = false; + if (argc - 1 >= i + 1) + { + gwip = argv[i + 1]; + i++; + } + else + { + badarg = true; + } } - else + else if (!strcmp(tmp, "netmask")) { - tmp = argv[i]; - - if (!strcmp(tmp, "dr") || !strcmp(tmp, "gw") || - !strcmp(tmp, "gateway")) + if (argc - 1 >= i + 1) { - if (argc - 1 >= i + 1) - { - gwip = argv[i + 1]; - i++; - } - else - { - badarg = true; - } + mask = argv[i + 1]; + i++; } - else if (!strcmp(tmp, "netmask")) + else { - if (argc - 1 >= i + 1) - { - mask = argv[i + 1]; - i++; - } - else - { - badarg = true; - } + badarg = true; } - else if (!strcmp(tmp, "inet")) - { + } + else if (!strcmp(tmp, "inet")) + { #if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) - inet6 = false; + inet6 = false; #elif !defined(CONFIG_NET_IPv4) - badarg = true; + badarg = true; #endif - } - else if (!strcmp(tmp, "inet6")) - { + } + else if (!strcmp(tmp, "inet6")) + { #if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) - inet6 = true; + inet6 = true; #elif !defined(CONFIG_NET_IPv6) - badarg = true; + badarg = true; #endif - } + } #ifdef CONFIG_NET_IPv6 - else if (!strcmp(tmp, "prefixlen")) + else if (!strcmp(tmp, "prefixlen")) + { + if (argc - 1 >= i + 1) { - if (argc - 1 >= i + 1) - { - preflen = argv[i + 1]; - i++; - } - else - { - badarg = true; - } + preflen = argv[i + 1]; + i++; } + else + { + badarg = true; + } + } #endif #ifdef HAVE_HWADDR - /* REVISIT: How will we handle Ethernet and SLIP together? */ + /* REVISIT: How will we handle Ethernet and SLIP together? */ - else if (!strcmp(tmp, "hw")) + else if (!strcmp(tmp, "hw")) + { + if (argc - 1 >= i + 1) { - if (argc - 1 >= i + 1) - { - hw = argv[i + 1]; - i++; + hw = argv[i + 1]; + i++; - badarg = nsh_addrconv(hw, &macaddr); - } - else - { - badarg = true; - } + badarg = nsh_addrconv(hw, &macaddr); } + else + { + badarg = true; + } + } #endif #ifdef CONFIG_NETDB_DNSCLIENT - else if (!strcmp(tmp, "dns")) + else if (!strcmp(tmp, "dns")) + { + if (argc - 1 >= i + 1) { - if (argc - 1 >= i + 1) - { - dns = argv[i + 1]; - i++; - } - else - { - badarg = true; - } + dns = argv[i + 1]; + i++; } -#endif - else if (!strcmp(tmp, "add")) + else { -#if defined(CONFIG_NET_IPv6) && defined(CONFIG_NETDEV_MULTIPLE_IPv6) - remove = false; - continue; + badarg = true; } - else if (!strcmp(tmp, "del")) - { - remove = true; + } #endif - continue; - } - else if (!strcmp(tmp, "mtu")) + else if (!strcmp(tmp, "add")) + { +#if defined(CONFIG_NET_IPv6) && defined(CONFIG_NETDEV_MULTIPLE_IPv6) + remove = false; + continue; + } + else if (!strcmp(tmp, "del")) + { + remove = true; +#endif + continue; + } + else if (!strcmp(tmp, "mtu")) + { + if (argc - 1 >= i + 1) { - if (argc - 1 >= i + 1) + mtu = atoi(argv[i + 1]); + i++; + if (mtu < 1280) { - mtu = atoi(argv[i + 1]); - i++; - if (mtu < 1280) - { - mtu = 1280; - } - } - else - { - badarg = true; + mtu = 1280; } } -#ifdef CONFIG_NET_ARP - else if (!strcmp(tmp, "arp")) + else { - /* Enable arp function on interface */ - - arpflag = ARP_ENABLE; + badarg = true; } - else if (!strcmp(tmp, "-arp")) - { - /* Disable arp function on interface */ + } +#ifdef CONFIG_NET_ARP + else if (!strcmp(tmp, "arp")) + { + /* Enable arp function on interface */ - arpflag = ARP_DISABLE; - } + arpflag = ARP_ENABLE; + } + else if (!strcmp(tmp, "-arp")) + { + /* Disable arp function on interface */ + + arpflag = ARP_DISABLE; + } #endif - else if (hostip == NULL && i <= 4) - { - /* Let first non-option be host ip, to support inet/inet6 - * options before address. - */ + else if (hostip == NULL && i <= 4) + { + /* Let first non-option be host ip, to support inet/inet6 + * options before address. + */ - hostip = tmp; - } - else - { - badarg = true; - } + hostip = tmp; + } + else + { + badarg = true; } } }
