changeset 21776:1e81dd035639 stable

Write integers with correct byte order on big-endian systems (bug #47434) * oct-stream.cc (convert_data, octave_stream::write): Fix logic error in determination of whether to swap bytes on big-endian systems.
author Mike Miller <mtmiller@octave.org>
date Wed, 25 May 2016 12:21:59 -0700
parents 7496bd7265d9
children d6826b38b29c 3bbc8e89a24c
files libinterp/corefcn/oct-stream.cc
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/oct-stream.cc	Tue May 24 11:44:45 2016 -0700
+++ b/libinterp/corefcn/oct-stream.cc	Wed May 25 12:21:59 2016 -0700
@@ -3631,10 +3631,12 @@
 {
   bool retval = true;
 
-  bool swap
-    = ((oct_mach_info::words_big_endian ()
-        && flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian)
-       || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian);
+  bool swap = false;
+
+  if (oct_mach_info::words_big_endian ())
+    swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian);
+  else
+    swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian);
 
   bool do_float_conversion =  flt_fmt != oct_mach_info::float_format ();
 
@@ -3800,9 +3802,12 @@
                       octave_idx_type skip,
                       oct_mach_info::float_format flt_fmt)
 {
-  bool swap = ((oct_mach_info::words_big_endian ()
-                && flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian)
-               || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian);
+  bool swap = false;
+
+  if (oct_mach_info::words_big_endian ())
+    swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian);
+  else
+    swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian);
 
   bool do_data_conversion = (swap || ! is_equivalent_type<T> (output_type)
                              || flt_fmt != oct_mach_info::float_format ());