From ff9df4c1b0525287bd6823616936f36837c9ac99 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Thu, 17 Oct 2024 14:44:10 +0000 Subject: [PATCH 1/4] Per #2673, switch to STL vector to attempt to squash a SonarQube bug. --- src/libcode/vx_python3_utils/wchar_argv.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libcode/vx_python3_utils/wchar_argv.cc b/src/libcode/vx_python3_utils/wchar_argv.cc index ff26b0d21..e3e0586a8 100644 --- a/src/libcode/vx_python3_utils/wchar_argv.cc +++ b/src/libcode/vx_python3_utils/wchar_argv.cc @@ -191,8 +191,6 @@ void Wchar_Argv::set(int _argc, char ** _argv) clear(); int k; -int *len = new int [_argc]; - Argc = _argc; @@ -201,13 +199,14 @@ Argc = _argc; // int argv_len = 0; +vector len(_argc, 0); for (int j=0; j<_argc; ++j) { // we're using the len array here because // we don't want to call m_strlen more than // once on each argv value - len[j] = (_argv == nullptr) ? 0 : len[j] = m_strlen(_argv[j]); + if (_argv) len[j] = m_strlen(_argv[j]); argv_len += len[j]; @@ -276,8 +275,6 @@ for (int j=0; j Date: Thu, 17 Oct 2024 15:27:28 +0000 Subject: [PATCH 2/4] Per #2673, remove m_strlen() entirely. --- src/libcode/vx_python3_utils/wchar_argv.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libcode/vx_python3_utils/wchar_argv.cc b/src/libcode/vx_python3_utils/wchar_argv.cc index e3e0586a8..d0bd156f9 100644 --- a/src/libcode/vx_python3_utils/wchar_argv.cc +++ b/src/libcode/vx_python3_utils/wchar_argv.cc @@ -206,7 +206,10 @@ for (int j=0; j<_argc; ++j) { // we're using the len array here because // we don't want to call m_strlen more than // once on each argv value - if (_argv) len[j] = m_strlen(_argv[j]); + if (_argv) { + string arg_str = _argv[j]; + len[j] = arg_str.length(); + } argv_len += len[j]; From 52a61294f9fe0af9db299b8958f82e3a320fc12f Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Thu, 17 Oct 2024 16:02:06 +0000 Subject: [PATCH 3/4] Per #2673, try again ci-skip-unit --- src/libcode/vx_python3_utils/wchar_argv.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libcode/vx_python3_utils/wchar_argv.cc b/src/libcode/vx_python3_utils/wchar_argv.cc index d0bd156f9..31e4ca692 100644 --- a/src/libcode/vx_python3_utils/wchar_argv.cc +++ b/src/libcode/vx_python3_utils/wchar_argv.cc @@ -206,10 +206,7 @@ for (int j=0; j<_argc; ++j) { // we're using the len array here because // we don't want to call m_strlen more than // once on each argv value - if (_argv) { - string arg_str = _argv[j]; - len[j] = arg_str.length(); - } + if (_argv && _argv[j]) len[j] = m_strlen(_argv[j]); argv_len += len[j]; From 342358dae6985bb3a8af1d1e135510d776415c13 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Thu, 17 Oct 2024 18:38:23 +0000 Subject: [PATCH 4/4] Per #2673, switching to 2 more vectors --- src/libcode/vx_python3_utils/wchar_argv.cc | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/libcode/vx_python3_utils/wchar_argv.cc b/src/libcode/vx_python3_utils/wchar_argv.cc index 31e4ca692..2a760edba 100644 --- a/src/libcode/vx_python3_utils/wchar_argv.cc +++ b/src/libcode/vx_python3_utils/wchar_argv.cc @@ -146,36 +146,29 @@ for (int j=0; j<(a.n()); ++j) { int N = len + a.n(); -char * s = new char [N]; - -char ** av = new char * [a.n()]; - -memset(s, 0, N); +vector s(N, 0); +vector av(a.n(), nullptr); for (int j=0; j<(a.n()); ++j) { - av[j] = s + k; - c = a[j].c_str(); len = c.length(); - m_strncpy(s + k, c.text(), len, method_name); + m_strncpy(s.data() + k, c.text(), len, method_name); + + av[j] = s.data() + k; k += (len + 1); } -set(a.n(), av); +set(a.n(), av.data()); // // done // -if ( s ) { delete [] s; s = nullptr; } - -if ( av ) { delete [] av; av = nullptr; } - return; } @@ -206,7 +199,7 @@ for (int j=0; j<_argc; ++j) { // we're using the len array here because // we don't want to call m_strlen more than // once on each argv value - if (_argv && _argv[j]) len[j] = m_strlen(_argv[j]); + if (_argv) len[j] = m_strlen(_argv[j]); argv_len += len[j];