Mercurial > octave
diff libinterp/corefcn/load-save.cc @ 25604:ca413f326224
Fix lifetime issues with temporary char arrays returned by get_ASCII_filename (bug #54299).
* debug.cc, dlmread.cc, help.cc, load-save.cc, ls-hdf5.cc, urlwrite.cc,
ov-java.cc, file-info.cc, url-transfer.cc: Assign return value of
get_ASCII_filename to variable to fix lifetime errors with the previous
approach.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Fri, 13 Jul 2018 19:13:23 +0200 |
parents | c71d13bf2b63 |
children | 4d565baa475e |
line wrap: on
line diff
--- a/libinterp/corefcn/load-save.cc Fri Jul 13 09:16:26 2018 -0700 +++ b/libinterp/corefcn/load-save.cc Fri Jul 13 19:13:23 2018 +0200 @@ -226,7 +226,9 @@ { bool retval = false; - std::ifstream file (octave::sys::get_ASCII_filename (fname).c_str (), + std::string ascii_fname = octave::sys::get_ASCII_filename (fname); + + std::ifstream file (ascii_fname.c_str (), std::ios::in | std::ios::binary); unsigned char magic[2]; @@ -313,9 +315,11 @@ { load_save_format retval = LS_UNKNOWN; + std::string ascii_fname = octave::sys::get_ASCII_filename (fname); + #if defined (HAVE_HDF5) // check this before we open the file - if (H5Fis_hdf5 (octave::sys::get_ASCII_filename (fname).c_str ()) > 0) + if (H5Fis_hdf5 (ascii_fname.c_str ()) > 0) return LS_HDF5; #endif @@ -327,7 +331,7 @@ if (! use_zlib) { - std::ifstream file (octave::sys::get_ASCII_filename (fname).c_str (), + std::ifstream file (ascii_fname.c_str (), std::ios::in | std::ios::binary); if (file) { @@ -836,8 +840,9 @@ else #endif { - std::ifstream file ( - octave::sys::get_ASCII_filename (fname).c_str (), mode); + std::string ascii_fname = octave::sys::get_ASCII_filename (fname); + + std::ifstream file (ascii_fname.c_str (), mode); if (! file) error ("load: unable to open input file '%s'", @@ -1700,9 +1705,10 @@ if (append) error ("save: appending to HDF5 files is not implemented"); + std::string ascii_fname = octave::sys::get_ASCII_filename (fname); + bool write_header_info - = ! (append && H5Fis_hdf5 ( - octave::sys::get_ASCII_filename (fname).c_str ()) > 0); + = ! (append && H5Fis_hdf5 (ascii_fname.c_str ()) > 0); hdf5_ofstream hdf5_file (fname.c_str (), mode);