changeset 19367:a791930c3bda stable

oct-stream.cc::read: Fix calculation of nc when EOF gets hit (bug #43517) * oct-stream.cc::read: Fix nc if EOF was hit before the requested number of rows and columns were read. * io.tst: Add test for bug #43517
author Andreas Weber <andy.weber.aw@gmail.com>
date Fri, 14 Nov 2014 22:35:19 +0100
parents ed1bf35dc11c
children 1213af866a89
files libinterp/corefcn/oct-stream.cc test/io.tst
diffstat 2 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/oct-stream.cc	Mon Nov 03 22:07:27 2014 -0800
+++ b/libinterp/corefcn/oct-stream.cc	Fri Nov 14 22:35:19 2014 +0100
@@ -3330,6 +3330,8 @@
                 {
                   if (count % nr != 0)
                     nc = count / nr + 1;
+                  else
+                    nc = count / nr;
 
                   if (count < nr)
                     nr = count;
--- a/test/io.tst	Mon Nov 03 22:07:27 2014 -0800
+++ b/test/io.tst	Fri Nov 14 22:35:19 2014 +0100
@@ -604,3 +604,12 @@
 %! assert (data, [256, 1798; 770, 3083; 1284, 3597]);
 %! assert (count, 6);
 %! fclose (id);
+
+%!test
+%! id = tmpfile ();
+%! fwrite (id, "abcd");
+%! frewind (id);
+%! [data, count] = fread (id, [2, 3], "char");
+%! assert (data, [97, 99; 98, 100]);
+%! assert (count, 4);
+%! fclose (id);