Mercurial > octave
diff src/main-gui.cc @ 30192:8c8031be8072
Windows: Don't get pointers to C strings while vector is still unstable.
* src/main-cli.cc, src/main-gui.cc, src/main.in.cc, src/octave-config.in.cc,
src/octave-svgconvert.cc: The memory used by a vector is not guaranteed to be
stable when elements are added with push_back. Wait until vector is complete
before getting the pointers to the corresponding C strings.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Thu, 16 Sep 2021 21:51:03 +0200 |
parents | 96eb9a6f868b |
children | 796f54d4ddbf |
line wrap: on
line diff
--- a/src/main-gui.cc Thu Sep 16 21:12:15 2021 -0400 +++ b/src/main-gui.cc Thu Sep 16 21:51:03 2021 +0200 @@ -111,12 +111,11 @@ // convert wide character strings to multibyte UTF-8 strings std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv; for (int i_arg = 0; i_arg < argc; i_arg++) - { - argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg])); + argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg])); - // Save the string because argv_str[i_arg] may return a temporary. - argv[i_arg] = octave::strsave (&argv_str[i_arg][0]); - } + // Get pointers to C strings not before vector is stable. + for (int i_arg = 0; i_arg < argc; i_arg++) + argv[i_arg] = &argv_str[i_arg][0]; argv[argc] = nullptr; #else