diff libinterp/corefcn/oct-stream.cc @ 20500:44eb1102f8a8

don't recycle scanf format string if all conversions are done (bug #45808) * oct-stream.cc, oct-stream.h (scanf_format_elt::special_conversion): New enum value, no_conversion. (scanf_format_list::next): If not cycling through the list, return dummy scanf_format_elt after list has been exhausted. (octave_base_stream::do_scanf): Only cycle through the format list more than once if there are conversions to make and the limit on the number of values to convert has not been reached.
author John W. Eaton <jwe@octave.org>
date Wed, 26 Aug 2015 16:05:49 -0400
parents a76e20f2f156
children 1a0a433c8263
line wrap: on
line diff
--- a/libinterp/corefcn/oct-stream.cc	Wed Aug 26 22:51:59 2015 +0200
+++ b/libinterp/corefcn/oct-stream.cc	Wed Aug 26 16:05:49 2015 -0400
@@ -1603,11 +1603,19 @@
 
           if (elt)
             {
-              if (! (elt->type == scanf_format_elt::whitespace_conversion
-                     || elt->type == scanf_format_elt::literal_conversion
-                     || elt->type == '%')
-                  && max_conv > 0 && conversion_count == max_conv)
+              if (elt->type == scanf_format_elt::null
+                  || (! (elt->type == scanf_format_elt::whitespace_conversion
+                        || elt->type == scanf_format_elt::literal_conversion
+                        || elt->type == '%')
+                      && max_conv > 0 && conversion_count == max_conv))
                 {
+                  // We are done, either because we have reached the end
+                  // of the format string and are not cycling through
+                  // the format again or because we've converted all the
+                  // values that have been requested and the next format
+                  // element is a conversion.  Determine final array
+                  // size and exit.
+
                   if (all_char_conv && one_elt_size_spec)
                     {
                       final_nr = 1;
@@ -1859,7 +1867,16 @@
               break;
             }
           else
-            elt = fmt_list.next (nconv > 0);
+            {
+              // Cycle through the format list more than once if we have
+              // some conversions to make and we haven't reached the
+              // limit on the number of values to convert (possibly
+              // because there is no specified limit).
+
+              elt = fmt_list.next (nconv > 0
+                                   && (max_conv == 0
+                                       || conversion_count < max_conv));
+            }
         }
     }