Mercurial > octave
changeset 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 | e55fb9685803 |
children | beef68dedef7 |
files | libinterp/corefcn/debug.cc libinterp/corefcn/dlmread.cc libinterp/corefcn/help.cc libinterp/corefcn/load-save.cc libinterp/corefcn/ls-hdf5.cc libinterp/corefcn/urlwrite.cc libinterp/octave-value/ov-java.cc liboctave/util/file-info.cc liboctave/util/url-transfer.cc |
diffstat | 9 files changed, 56 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/debug.cc Fri Jul 13 09:16:26 2018 -0700 +++ b/libinterp/corefcn/debug.cc Fri Jul 13 19:13:23 2018 +0200 @@ -594,7 +594,9 @@ os << "dbtype: unknown function " << name << "\n"; else { - std::ifstream fs (octave::sys::get_ASCII_filename (ff).c_str (), std::ios::in); + std::string ascii_fname = octave::sys::get_ASCII_filename (ff); + + std::ifstream fs (ascii_fname.c_str (), std::ios::in); if (! fs) os << "dbtype: unable to open '" << ff << "' for reading!\n";
--- a/libinterp/corefcn/dlmread.cc Fri Jul 13 09:16:26 2018 -0700 +++ b/libinterp/corefcn/dlmread.cc Fri Jul 13 19:13:23 2018 +0200 @@ -221,7 +221,9 @@ tname = find_data_file_in_load_path ("dlmread", tname); - input_file.open (octave::sys::get_ASCII_filename (tname).c_str (), std::ios::in); + std::string ascii_fname = octave::sys::get_ASCII_filename (tname); + + input_file.open (ascii_fname.c_str (), std::ios::in); if (! input_file) error ("dlmread: unable to open file '%s'", fname.c_str ());
--- a/libinterp/corefcn/help.cc Fri Jul 13 09:16:26 2018 -0700 +++ b/libinterp/corefcn/help.cc Fri Jul 13 19:13:23 2018 +0200 @@ -582,9 +582,11 @@ if (! initialized) { - std::ifstream file ( - octave::sys::get_ASCII_filename (m_built_in_docstrings_file).c_str (), - std::ios::in | std::ios::binary); + std::string ascii_fname + = octave::sys::get_ASCII_filename (m_built_in_docstrings_file); + + std::ifstream file (ascii_fname.c_str (), + std::ios::in | std::ios::binary); if (! file) error ("failed to open docstrings file: %s", @@ -666,9 +668,11 @@ std::streampos beg = txt_limits.first; std::streamoff len = txt_limits.second; - std::ifstream file ( - octave::sys::get_ASCII_filename (m_built_in_docstrings_file).c_str (), - std::ios::in | std::ios::binary); + std::string ascii_fname + = octave::sys::get_ASCII_filename (m_built_in_docstrings_file); + + std::ifstream file (ascii_fname.c_str (), + std::ios::in | std::ios::binary); if (! file) error ("failed to open docstrings file: %s",
--- 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);
--- a/libinterp/corefcn/ls-hdf5.cc Fri Jul 13 09:16:26 2018 -0700 +++ b/libinterp/corefcn/ls-hdf5.cc Fri Jul 13 19:13:23 2018 +0200 @@ -89,8 +89,11 @@ { #if defined (HAVE_HDF5) - const char *s_name = - octave::sys::get_ASCII_filename (std::string (name)).c_str (); + std::string fname (name); + + std::string ascii_fname = octave::sys::get_ASCII_filename (fname); + + const char *s_name = ascii_fname.c_str (); if (mode & std::ios::in) file_id = H5Fopen (s_name, H5F_ACC_RDONLY, octave_H5P_DEFAULT); @@ -142,7 +145,11 @@ clear (); - const char *s_name = octave::sys::get_ASCII_filename (std::string (name)).c_str (); + std::string fname (name); + + std::string ascii_fname = octave::sys::get_ASCII_filename (fname); + + const char *s_name = ascii_fname.c_str (); if (mode & std::ios::in) file_id = H5Fopen (s_name, H5F_ACC_RDONLY, octave_H5P_DEFAULT);
--- a/libinterp/corefcn/urlwrite.cc Fri Jul 13 09:16:26 2018 -0700 +++ b/libinterp/corefcn/urlwrite.cc Fri Jul 13 19:13:23 2018 +0200 @@ -637,8 +637,10 @@ } else { + std::string ascii_fname = octave::sys::get_ASCII_filename (file); + // FIXME: Does ascii mode need to be flagged here? - std::ifstream ifile (octave::sys::get_ASCII_filename (file).c_str (), + std::ifstream ifile (ascii_fname.c_str (), std::ios::in | std::ios::binary); if (! ifile.is_open ())
--- a/libinterp/octave-value/ov-java.cc Fri Jul 13 09:16:26 2018 -0700 +++ b/libinterp/octave-value/ov-java.cc Fri Jul 13 19:13:23 2018 +0200 @@ -238,7 +238,9 @@ void read_java_opts (const std::string& filename) { - std::ifstream js (octave::sys::get_ASCII_filename (filename).c_str ()); + std::string ascii_fname = octave::sys::get_ASCII_filename (filename); + + std::ifstream js (ascii_fname.c_str ()); if (! js.bad () && ! js.fail ()) { @@ -359,7 +361,9 @@ { std::string classpath; - std::ifstream fs (octave::sys::get_ASCII_filename (filepath).c_str ()); + std::string ascii_fname = octave::sys::get_ASCII_filename (filepath); + + std::ifstream fs (ascii_fname.c_str ()); if (! fs.bad () && ! fs.fail ()) {
--- a/liboctave/util/file-info.cc Fri Jul 13 09:16:26 2018 -0700 +++ b/liboctave/util/file-info.cc Fri Jul 13 19:13:23 2018 +0200 @@ -81,8 +81,9 @@ size_t sz = fs.size (); - std::ifstream file (octave::sys::get_ASCII_filename (fname).c_str (), - std::ios::in | std::ios::binary); + std::string ascii_fname = octave::sys::get_ASCII_filename (fname); + + std::ifstream file (ascii_fname.c_str (), std::ios::in | std::ios::binary); if (file) {
--- a/liboctave/util/url-transfer.cc Fri Jul 13 09:16:26 2018 -0700 +++ b/liboctave/util/url-transfer.cc Fri Jul 13 19:13:23 2018 +0200 @@ -202,9 +202,11 @@ else { // FIXME: Does ascii mode need to be flagged here? - std::ifstream ifile ( - octave::sys::get_ASCII_filename (realfile).c_str (), - std::ios::in | std::ios::binary); + std::string ascii_fname + = octave::sys::get_ASCII_filename (realfile); + + std::ifstream ifile (ascii_fname.c_str (), + std::ios::in | std::ios::binary); if (! ifile.is_open ()) {