From 4f997234d9db3743add68cd409ae33ba33b29494 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Thu, 17 Oct 2024 13:58:44 -0600 Subject: [PATCH] Feature #2673 wchar argv (#2999) * Per #2673, switch to STL vector to attempt to squash a SonarQube bug. * Per #2673, remove m_strlen() entirely. * Per #2673, try again ci-skip-unit * Per #2673, switching to 2 more vectors --- src/libcode/vx_python3_utils/wchar_argv.cc | 26 +++++++--------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/libcode/vx_python3_utils/wchar_argv.cc b/src/libcode/vx_python3_utils/wchar_argv.cc index ff26b0d21..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; } @@ -191,8 +184,6 @@ void Wchar_Argv::set(int _argc, char ** _argv) clear(); int k; -int *len = new int [_argc]; - Argc = _argc; @@ -201,13 +192,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 +268,6 @@ for (int j=0; j