From 8b0bdae88395c73aa200f35e643b710a44cb07ad Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 9 Feb 2025 00:45:46 +0100 Subject: [PATCH] NetCon: fix command line parsing bug -ansicolor is the only possible command line parameter, if its passed we need to shift the indices for the next one if user provided address and key. --- src/netconsole/netconsole.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/netconsole/netconsole.cpp b/src/netconsole/netconsole.cpp index dc8fbe05..33636bf4 100644 --- a/src/netconsole/netconsole.cpp +++ b/src/netconsole/netconsole.cpp @@ -511,27 +511,23 @@ int main(int argc, char* argv[]) bool bEnableColor = false; - for (int i = 0; i < argc; i++) + if (argc >= 2) { - if (V_strcmp(argv[i], "-ansicolor") == NULL) - { - bEnableColor = true; - break; - } + bEnableColor = V_strcmp(argv[1], "-ansicolor") == NULL; } // The address and key from command line if passed in. const char* pAdr = nullptr; const char* pKey = nullptr; - if (argc >= 2) + if (argc >= 2 + bEnableColor) { - pAdr = argv[1]; + pAdr = argv[1 + bEnableColor]; } - if (argc >= 3) + if (argc >= 3 + bEnableColor) { - pKey = argv[2]; + pKey = argv[2 + bEnableColor]; } if (!NetConsole()->Init(bEnableColor, pAdr, pKey))