Mercurial > octave
comparison src/main.in.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 | 218716316e62 |
children | e1b0ed07895b |
comparison
equal
deleted
inserted
replaced
30191:57aac5b9cf9d | 30192:8c8031be8072 |
---|---|
227 std::vector<std::string> argv_str; | 227 std::vector<std::string> argv_str; |
228 | 228 |
229 // convert wide character strings to multibyte UTF-8 strings | 229 // convert wide character strings to multibyte UTF-8 strings |
230 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv; | 230 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv; |
231 for (int i_arg = 0; i_arg < argc; i_arg++) | 231 for (int i_arg = 0; i_arg < argc; i_arg++) |
232 { | 232 argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg])); |
233 argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg])); | 233 |
234 argv[i_arg] = &argv_str[i_arg][0]; | 234 // Get pointers to C strings not before vector is stable. |
235 } | 235 for (int i_arg = 0; i_arg < argc; i_arg++) |
236 argv[i_arg] = &argv_str[i_arg][0]; | |
236 argv[argc] = nullptr; | 237 argv[argc] = nullptr; |
237 | 238 |
238 #else | 239 #else |
239 int | 240 int |
240 main (int argc, char **argv) | 241 main (int argc, char **argv) |