Mercurial > hg > octave-shane
changeset 16074:821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
* liboctave/util/data-conv.cc(LS_DO_READ, LS_DO_WRITE, read_doubles,
read_floats, write_doubles, write_floats): Calculate number of bytes
to read/write using std::streamsize variable rather than octave_idx_type.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 20 Feb 2013 14:58:39 -0800 |
parents | 1c8234f0b642 |
children | 7cfb186592de |
files | liboctave/util/data-conv.cc |
diffstat | 1 files changed, 19 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/util/data-conv.cc +++ b/liboctave/util/data-conv.cc @@ -487,7 +487,8 @@ if (len > 0) \ { \ OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ - stream.read (reinterpret_cast<char *> (ptr), size * len); \ + std::streamsize n_bytes = size * len; \ + stream.read (reinterpret_cast<char *> (ptr), n_bytes); \ if (swap) \ swap_bytes< size > (ptr, len); \ for (octave_idx_type i = 0; i < len; i++) \ @@ -509,7 +510,8 @@ OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ for (octave_idx_type i = 0; i < len; i++) \ ptr[i] = static_cast <TYPE> (data[i]); \ - stream.write (reinterpret_cast<char *> (ptr), size * len); \ + std::streamsize n_bytes = size * len; \ + stream.write (reinterpret_cast<char *> (ptr), n_bytes); \ } \ } \ while (0) @@ -1008,7 +1010,6 @@ } } - void read_doubles (std::istream& is, double *data, save_type type, octave_idx_type len, bool swap, @@ -1043,7 +1044,8 @@ case LS_FLOAT: { OCTAVE_LOCAL_BUFFER (float, ptr, len); - is.read (reinterpret_cast<char *> (ptr), 4 * len); + std::streamsize n_bytes = 4 * len; + is.read (reinterpret_cast<char *> (ptr), n_bytes); do_float_format_conversion (ptr, len, fmt); for (octave_idx_type i = 0; i < len; i++) data[i] = ptr[i]; @@ -1052,7 +1054,8 @@ case LS_DOUBLE: // No conversion necessary. { - is.read (reinterpret_cast<char *> (data), 8 * len); + std::streamsize n_bytes = 8 * static_cast<std::streamsize> (len); + is.read (reinterpret_cast<char *> (data), n_bytes); do_double_format_conversion (data, len, fmt); for (int i = 0; i < len; i++) @@ -1098,14 +1101,18 @@ break; case LS_FLOAT: // No conversion necessary. - is.read (reinterpret_cast<char *> (data), 4 * len); - do_float_format_conversion (data, len, fmt); + { + std::streamsize n_bytes = 4 * len; + is.read (reinterpret_cast<char *> (data), n_bytes); + do_float_format_conversion (data, len, fmt); + } break; case LS_DOUBLE: { OCTAVE_LOCAL_BUFFER (double, ptr, len); - is.read (reinterpret_cast<char *> (ptr), 8 * len); + std::streamsize n_bytes = 8 * len; + is.read (reinterpret_cast<char *> (ptr), n_bytes); do_double_format_conversion (ptr, len, fmt); for (octave_idx_type i = 0; i < len; i++) data[i] = ptr[i]; @@ -1156,7 +1163,8 @@ { char tmp_type = static_cast<char> (type); os.write (&tmp_type, 1); - os.write (reinterpret_cast <const char *> (data), 8 * len); + std::streamsize n_bytes = 8 * static_cast<std::streamsize> (len); + os.write (reinterpret_cast <const char *> (data), n_bytes); } break; @@ -1201,7 +1209,8 @@ { char tmp_type = static_cast<char> (type); os.write (&tmp_type, 1); - os.write (reinterpret_cast <const char *> (data), 4 * len); + std::streamsize n_bytes = 4 * len; + os.write (reinterpret_cast <const char *> (data), n_bytes); } break;