# HG changeset patch # User jwe # Date 784440498 0 # Node ID a9b2b0f9abf6878143dfeb99ee6091d43f74a92d # Parent 5de3b53c0e02bb77d592b7ff28bd30000a639837 [project @ 1994-11-10 04:08:18 by jwe] diff -r 5de3b53c0e02 -r a9b2b0f9abf6 src/load-save.cc --- a/src/load-save.cc Thu Nov 10 01:48:13 1994 +0000 +++ b/src/load-save.cc Thu Nov 10 04:08:18 1994 +0000 @@ -1638,13 +1638,12 @@ { swap = 0; +// We expect to fail here, at the beginning of a record, so not being +// able to read another mopt value should not result in an error. + is.read (&mopt, 4); if (! is) - { - if (! is.eof ()) - goto data_read_error; - return 1; - } + return 1; if (! is.read (&nr, 4)) goto data_read_error; @@ -1672,7 +1671,9 @@ swap = 1; #endif - if (mopt > 9999) +// mopt is signed, therefore byte swap may result in negative value. + + if (mopt > 9999 || mopt < 0) swap = 1; if (swap) @@ -1684,7 +1685,7 @@ swap_4_bytes ((char *) &len); } - if (mopt > 9999 || imag > 1 || imag < 0 || len > 8192) + if (mopt > 9999 || mopt < 0 || imag > 1 || imag < 0) { if (! quiet) error ("load: can't read binary file"); @@ -2448,7 +2449,7 @@ double tmp = tc.double_value (); os.write (&tmp, 8); } - else if (tc.is_real_matrix () || tc.is_range ()) + else if (tc.is_real_matrix ()) { Matrix m = tc.matrix_value (); os.write (m.data (), 8 * len); @@ -2475,6 +2476,18 @@ os.write (m.data (), 8 * len); run_unwind_frame ("save_mat_binary_data"); } + else if (tc.is_range ()) + { + Range r = tc.range_value (); + double base = r.base (); + double inc = r.inc (); + int nel = r.nelem (); + for (int i = 0; i < nel; i++) + { + double x = base + i * inc; + os.write (&x, 8); + } + } else { gripe_wrong_type_arg ("save", tc); @@ -2793,6 +2806,9 @@ if (strcasecmp (fmt, "binary") == 0) retval = LS_BINARY; + else if (strcasecmp (fmt, "mat-binary") == 0 + || strcasecmp (fmt, "mat_binary") == 0) + retval = LS_MAT_BINARY; return retval; } @@ -2935,7 +2951,7 @@ argc--; argv++; - unsigned mode = ios::out; + unsigned mode = ios::out|ios::trunc; if (format == LS_BINARY || format == LS_MAT_BINARY) mode |= ios::bin;