changeset 30534:f69ddab4b0ec

get_ASCII_filename: Replace VLA with std::wstring. * liboctave/system/lo-sysdep.cc (get_ASCII_filename): Replace VLA with std::wstring.
author Gene Harvey <gharveymn@gmail.com>
date Mon, 27 Sep 2021 13:55:27 -0500
parents 5ff87e646505
children 91642eb6420e
files liboctave/system/lo-sysdep.cc
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/system/lo-sysdep.cc	Thu Dec 23 15:40:53 2021 +0100
+++ b/liboctave/system/lo-sysdep.cc	Mon Sep 27 13:55:27 2021 -0500
@@ -699,17 +699,19 @@
         = (oct_ascii_dir + file_ops::dir_sep_str ()
            + crypto::hash ("SHA1", orig_file_name));
 
+      // FIXME: This is just to check if the file exists.  Use a more efficient
+      // method.
       std::string abs_filename_hash = canonicalize_file_name (filename_hash);
 
       if (! abs_filename_hash.empty ())
         sys::unlink (filename_hash);
 
-      wchar_t w_filename_hash[filename_hash.length ()+1] = {0};
+      // At this point, we know that we have only ASCII characters.
+      // So instead of converting, just copy the characters to std::wstring.
+      std::wstring w_filename_hash (filename_hash.begin (),
+                                    filename_hash.end ());
 
-      for (std::size_t i=0; i < filename_hash.length (); i++)
-        w_filename_hash[i] = filename_hash.at (i);
-
-      if (CreateHardLinkW (w_filename_hash, w_orig_file_name, nullptr))
+      if (CreateHardLinkW (w_filename_hash.c_str (), w_orig_file_name, nullptr))
         return filename_hash;
 
 #else