changeset 26500:d76f9e42290a stable

oct-stream.cc: Fix static analyzer detected issues (bug #55347). * oct-stream.cc (scanf_format_list::finish_conversion): Pass width by value, not reference. * oct-stream.cc (printf_format_list::printf_format_list): Pass argument to process_conversion in the correct order of "modifier", "type" (accidentally reversed, but apparently no error). * oct-stream.cc (textscan_format_list::finish_conversion): Pass width, prec, and bitwidth argument by value rather than reference. * oct-stream.cc (textscan_format_list::read_first_row): Remove unneeded variable progress. * oct-stream.cc (textscan::do_scan): Enclose expression that is the subject of += operator in parentheses for clarity. * oct-stream.cc (textscan::read_double): Remove three useless test on "width_left".
author Rik <rik@octave.org>
date Tue, 08 Jan 2019 16:44:44 -0800
parents 9326e683c3a4
children cfe28edab48b
files libinterp/corefcn/oct-stream.cc
diffstat 1 files changed, 11 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/oct-stream.cc	Tue Jan 08 13:17:36 2019 -0800
+++ b/libinterp/corefcn/oct-stream.cc	Tue Jan 08 16:44:44 2019 -0800
@@ -358,7 +358,7 @@
                              char& modifier);
 
     int finish_conversion (const std::string& s, size_t& i, size_t n,
-                           int& width, bool discard, char& type,
+                           int width, bool discard, char& type,
                            char modifier);
   };
 
@@ -569,7 +569,7 @@
 
   int
   scanf_format_list::finish_conversion (const std::string& s, size_t& i,
-                                        size_t n, int& width, bool discard,
+                                        size_t n, int width, bool discard,
                                         char& type, char modifier)
   {
     int retval = 0;
@@ -890,7 +890,7 @@
                   if (empty_buf)
                     {
                       process_conversion (s, i, n, args, flags, fw, prec,
-                                          type, modifier);
+                                          modifier, type);
 
                       // If there is nothing in the buffer, then
                       // add_elt_to_list must have just been called, so we
@@ -1756,7 +1756,7 @@
     std::string parse_char_class (const std::string& pattern) const;
 
     int finish_conversion (const std::string& s, size_t& i, size_t n,
-                           unsigned int& width, int& prec, int& bitwidth,
+                           unsigned int width, int prec, int bitwidth,
                            octave_value& val_type,
                            bool discard, char& type);
   };
@@ -2333,8 +2333,8 @@
 
   int
   textscan_format_list::finish_conversion (const std::string& s, size_t& i,
-                                           size_t n, unsigned int& width,
-                                           int& prec, int& bitwidth,
+                                           size_t n, unsigned int width,
+                                           int prec, int bitwidth,
                                            octave_value& val_type, bool discard,
                                            char& type)
   {
@@ -2457,7 +2457,6 @@
         bool already_skipped_delim = false;
         ts.skip_whitespace (ds);
         ds.progress_benchmark ();
-        bool progress = false;
         ts.scan_complex (ds, *fmt_elts[0], val);
         if (ds.fail ())
           {
@@ -2492,7 +2491,7 @@
         if (! already_skipped_delim)
           ts.skip_delim (ds);
 
-        if (! progress && ds.no_progress ())
+        if (ds.no_progress ())
           break;
 
         nconv++;
@@ -2643,7 +2642,7 @@
           {
             if (row == 0 || row >= size)
               {
-                size += size+1;
+                size += (size+1);
                 for (auto& col : out)
                   col = col.resize (dim_vector (size, 1), 0);
               }
@@ -2786,8 +2785,7 @@
         int precision = fmt.prec;
         int i;
 
-        if (width_left)
-          width_left--;                // Consider width of '.'
+        width_left--;                  // Consider width of '.'
 
         if (precision == -1)
           precision = 1<<30;           // FIXME: Should be MAXINT
@@ -2835,16 +2833,14 @@
             int exp_sign = 1;
             if (ch1 == '+')
               {
-                if (width_left)
-                  width_left--;
+                width_left--;
                 is.get ();
               }
             else if (ch1 == '-')
               {
+                width_left--;
                 exp_sign = -1;
                 is.get ();
-                if (width_left)
-                  width_left--;
               }
             valid = false;
             while (width_left-- && is && (ch = is.get ()) >= '0' && ch <= '9')