diff liboctave/system/file-ops.cc @ 28175:b895daca20e2 stable

Avoid potential lifetime issues with temporary std::wstring objects. * sysdep.cc (F__open_with_system_app__, get_regkey_value, get_regkey_names), file-ops.cc (rename), lo-sysdep.cc (get_dirlist, fopen, getenv_wrapper), oct-shlib.cc (octave_w32_shlib): Explicitly create std::wstring object with well-defined lifetime when passing the pointer to the underlying c_str to a function.
author Markus Mützel <markus.muetzel@gmx.de>
date Fri, 27 Mar 2020 08:52:33 +0100
parents b70b9eaaf751
children 6ea1e96b69d4
line wrap: on
line diff
--- a/liboctave/system/file-ops.cc	Wed Mar 25 08:24:13 2020 -0700
+++ b/liboctave/system/file-ops.cc	Fri Mar 27 08:52:33 2020 +0100
@@ -516,8 +516,9 @@
       msg = "";
 
 #if defined (OCTAVE_USE_WINDOWS_API)
-      status = _wrename (u8_to_wstring (from).c_str (),
-                         u8_to_wstring (to).c_str ());
+      std::wstring wfrom = u8_to_wstring (from);
+      std::wstring wto = u8_to_wstring (to);
+      status = _wrename (wfrom.c_str (), wto.c_str ());
 #else
       status = std::rename (from.c_str (), to.c_str ());
 #endif