diff libinterp/corefcn/oct-stream.cc @ 18586:0bdecd41b2dd stable

correctly size fread result (bug #41648) * oct-stream.cc (octave_base_stream::read): When reading to EOF, don't add extra column to the result matrix if the number of elements found is an exact multiple of the number of rows requested. Avoid mixed signed/unsigned comparisons. * io.tst: New tests.
author John W. Eaton <jwe@octave.org>
date Sat, 22 Feb 2014 13:06:18 -0500
parents fdd27f68b011
children f958e8cd6348 aa861a98d84d
line wrap: on
line diff
--- a/libinterp/corefcn/oct-stream.cc
+++ b/libinterp/corefcn/oct-stream.cc
@@ -3276,7 +3276,7 @@
 
                   char_count += gcount;
 
-                  size_t nel = gcount / input_elt_size;
+                  octave_idx_type nel = gcount / input_elt_size;
 
                   count += nel;
 
@@ -3297,7 +3297,7 @@
                       // the original position?
                       seek (orig_pos, SEEK_SET);
 
-                      size_t remaining = eof_pos - orig_pos;
+                      off_t remaining = eof_pos - orig_pos;
 
                       if (remaining < skip)
                         seek (0, SEEK_END);
@@ -3312,7 +3312,12 @@
               if (read_to_eof)
                 {
                   if (nc < 0)
-                    nc = count / nr + 1;
+                    {
+                      nc = count / nr;
+
+                      if (count % nr != 0)
+                        nc ++;
+                    }
                   else
                     nr = count;
                 }