changeset 23401:e0c20a22da7e

eliminate some errors exposed by -fsanitize=undefined * graphics.in.h (axes::properties): Initialize non-property members. * Array.h (Array<T>::ArrayRep::ArrayRep): Always use new to initialize data member. * Sparse.h (Sparse<T>::SparseRep::SparseRep): Initialize d and r data members. * idx-vector.cc, idx-vector.h: Explicitly mention idx_base_rep in constructor initialization lists. (idx_vector::idx_vector_rep::as_array): Avoid passing null pointer to memcpy. (idx_vector::idx_colon_rep::idx_colon_rep): Use default for trivial constructor. (idx_vector::idx_range_rep::idx_range_rep): Delete trivial construtor. (idx_vector::idx_scalar_rep::idx_scalar_rep): Likewise. (idx_vector::idx_mask_rep::idx_mask_rep): Likewise. * Container.cc (Container::childEvent): Only set mouse tracking for child widgets as they are added.
author John W. Eaton <jwe@octave.org>
date Sat, 15 Apr 2017 11:54:33 -0400
parents b5ee9b985a82
children 1fadf480a63b
files libgui/graphics/Container.cc libinterp/corefcn/graphics.in.h liboctave/array/Array.h liboctave/array/Sparse.h liboctave/array/idx-vector.cc liboctave/array/idx-vector.h
diffstat 6 files changed, 128 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/Container.cc	Sat Apr 15 10:25:53 2017 -0700
+++ b/libgui/graphics/Container.cc	Sat Apr 15 11:54:33 2017 -0400
@@ -106,9 +106,21 @@
   void
   Container::childEvent (QChildEvent* xevent)
   {
-    if (xevent->child ()->isWidgetType ())
-      qobject_cast<QWidget*> (xevent->child ())->setMouseTracking (
-        hasMouseTracking ());
+    // Enable mouse tracking in child widgets as they are added if the
+    // container also has mouse tracking enabled.  There is no need to
+    // do this when child objects are removed.
+
+    if (xevent->added ())
+      {
+        QObject *obj = xevent->child ();
+
+        if (obj && obj->isWidgetType ())
+          {
+            QWidget *widget = qobject_cast<QWidget*> (obj);
+
+            if (widget)
+              widget->setMouseTracking (hasMouseTracking ());
+          }
+      }
   }
-
 }
--- a/libinterp/corefcn/graphics.in.h	Sat Apr 15 10:25:53 2017 -0700
+++ b/libinterp/corefcn/graphics.in.h	Sat Apr 15 11:54:33 2017 -0400
@@ -3881,21 +3881,60 @@
     void update_fontunits (const caseless_str& old_fontunits);
 
   private:
-    scaler sx, sy, sz;
-    Matrix x_render, x_render_inv;
-    Matrix x_gl_mat1, x_gl_mat2;
-    Matrix x_zlim;
-    std::list<octave_value> zoom_stack;
+
+    scaler sx = scaler ();
+    scaler sy = scaler ();
+    scaler sz = scaler ();
+
+    Matrix x_render = Matrix ();
+    Matrix x_render_inv = Matrix ();
+    Matrix x_gl_mat1 = Matrix ();
+    Matrix x_gl_mat2 = Matrix ();
+    Matrix x_zlim = Matrix ();
+
+    std::list<octave_value> zoom_stack = std::list<octave_value> ();
 
     // Axes layout data
-    int xstate, ystate, zstate;
-    double xPlane, xPlaneN, yPlane, yPlaneN, zPlane, zPlaneN;
-    double xpTick, xpTickN, ypTick, ypTickN, zpTick, zpTickN;
-    double fx, fy, fz;
-    double xticklen, yticklen, zticklen;
-    double xtickoffset, ytickoffset, ztickoffset;
-    bool x2Dtop, y2Dright, layer2Dtop, is2D;
-    bool xySym, xyzSym, zSign, nearhoriz;
+    int xstate = 0;
+    int ystate = 0;
+    int zstate = 0;
+
+    double xPlane = 0.0;
+    double yPlane = 0.0;
+    double zPlane = 0.0;
+
+    double xPlaneN = 0.0;
+    double yPlaneN = 0.0;
+    double zPlaneN = 0.0;
+
+    double xpTick = 0.0;
+    double ypTick = 0.0;
+    double zpTick = 0.0;
+
+    double xpTickN = 0.0;
+    double ypTickN = 0.0;
+    double zpTickN = 0.0;
+
+    double fx = 0.0;
+    double fy = 0.0;
+    double fz = 0.0;
+
+    double xticklen = 0.0;
+    double yticklen = 0.0;
+    double zticklen = 0.0;
+
+    double xtickoffset = 0.0;
+    double ytickoffset = 0.0;
+    double ztickoffset = 0.0;
+
+    bool x2Dtop = false;
+    bool y2Dright = false;
+    bool layer2Dtop = false;
+    bool is2D = false;
+    bool xySym = false;
+    bool xyzSym = false;
+    bool zSign = false;
+    bool nearhoriz = false;
 
     // Text renderer, used for calculation of text (tick labels) size
     octave::text_renderer txt_renderer;
--- a/liboctave/array/Array.h	Sat Apr 15 10:25:53 2017 -0700
+++ b/liboctave/array/Array.h	Sat Apr 15 11:54:33 2017 -0400
@@ -150,7 +150,10 @@
       std::copy (d, d+l, data);
     }
 
-    ArrayRep (void) : data (0), len (0), count (1) { }
+    // Use new instead of setting data to 0 so that fortran_vec and
+    // data always return valid addresses, even for zero-size arrays.
+
+    ArrayRep (void) : data (new T [0]), len (0), count (1) { }
 
     explicit ArrayRep (octave_idx_type n)
       : data (new T [n]), len (n), count (1) { }
--- a/liboctave/array/Sparse.h	Sat Apr 15 10:25:53 2017 -0700
+++ b/liboctave/array/Sparse.h	Sat Apr 15 11:54:33 2017 -0400
@@ -93,6 +93,12 @@
         c (new octave_idx_type [nc+1]), nzmx (nz), nrows (nr),
         ncols (nc), count (1)
     {
+      for (octave_idx_type i = 0; i < nz; i++)
+        d[i] = T ();
+
+      for (octave_idx_type i = 0; i < nz; i++)
+        r[i] = 0;
+
       for (octave_idx_type i = 0; i < nc + 1; i++)
         c[i] = 0;
     }
--- a/liboctave/array/idx-vector.cc	Sat Apr 15 10:25:53 2017 -0700
+++ b/liboctave/array/idx-vector.cc	Sat Apr 15 11:54:33 2017 -0400
@@ -80,6 +80,7 @@
 }
 
 idx_vector::idx_colon_rep::idx_colon_rep (char c)
+  : idx_base_rep ()
 {
   if (c != ':')
     {
@@ -115,7 +116,7 @@
 idx_vector::idx_range_rep::idx_range_rep (octave_idx_type _start,
                                           octave_idx_type _limit,
                                           octave_idx_type _step)
-  : start(_start),
+  : idx_base_rep (), start(_start),
     len (_step ? std::max ((_limit - _start) / _step,
                            static_cast<octave_idx_type> (0))
                : -1),
@@ -130,7 +131,7 @@
 }
 
 idx_vector::idx_range_rep::idx_range_rep (const Range& r)
-  : start (0), len (r.numel ()), step (1)
+  : idx_base_rep (), start (0), len (r.numel ()), step (1)
 {
   if (len < 0)
     err_invalid_range ();
@@ -263,7 +264,7 @@
 
 template <typename T>
 idx_vector::idx_scalar_rep::idx_scalar_rep (T x)
-  : data (0)
+  : idx_base_rep (), data (0)
 {
   octave_idx_type dummy = 0;
 
@@ -271,7 +272,7 @@
 }
 
 idx_vector::idx_scalar_rep::idx_scalar_rep (octave_idx_type i)
-  : data (i)
+  : idx_base_rep (), data (i)
 {
   if (data < 0)
     octave::err_invalid_index (data);
@@ -314,7 +315,8 @@
 
 template <typename T>
 idx_vector::idx_vector_rep::idx_vector_rep (const Array<T>& nda)
-  : data (0), len (nda.numel ()), ext (0), aowner (0), orig_dims (nda.dims ())
+  : idx_base_rep (), data (0), len (nda.numel ()), ext (0),
+    aowner (0), orig_dims (nda.dims ())
 {
   if (len != 0)
     {
@@ -330,7 +332,7 @@
 // Note that this makes a shallow copy of the index array.
 
 idx_vector::idx_vector_rep::idx_vector_rep (const Array<octave_idx_type>& inda)
-  : data (inda.data ()), len (inda.numel ()), ext (0),
+  : idx_base_rep (), data (inda.data ()), len (inda.numel ()), ext (0),
     aowner (new Array<octave_idx_type> (inda)), orig_dims (inda.dims ())
 {
   if (len != 0)
@@ -354,7 +356,7 @@
 
 idx_vector::idx_vector_rep::idx_vector_rep (const Array<octave_idx_type>& inda,
                                             octave_idx_type _ext, direct)
-  : data (inda.data ()), len (inda.numel ()), ext (_ext),
+  : idx_base_rep (), data (inda.data ()), len (inda.numel ()), ext (_ext),
     aowner (new Array<octave_idx_type> (inda)), orig_dims (inda.dims ())
 {
   // No checking.
@@ -370,7 +372,8 @@
 }
 
 idx_vector::idx_vector_rep::idx_vector_rep (bool b)
-  : data (0), len (b ? 1 : 0), ext (0), aowner (0), orig_dims (len, len)
+  : idx_base_rep (), data (0), len (b ? 1 : 0), ext (0), aowner (0),
+    orig_dims (len, len)
 {
   if (len != 0)
     {
@@ -383,7 +386,7 @@
 
 idx_vector::idx_vector_rep::idx_vector_rep (const Array<bool>& bnda,
                                             octave_idx_type nnz)
-  : data (0), len (nnz), ext (0), aowner (0), orig_dims ()
+  : idx_base_rep (), data (0), len (nnz), ext (0), aowner (0), orig_dims ()
 {
   if (nnz < 0)
     len = bnda.nnz ();
@@ -410,7 +413,8 @@
 }
 
 idx_vector::idx_vector_rep::idx_vector_rep (const Sparse<bool>& bnda)
-  : data (0), len (bnda.nnz ()), ext (0), aowner (0), orig_dims ()
+  : idx_base_rep (), data (0), len (bnda.nnz ()), ext (0), aowner (0),
+    orig_dims ()
 {
   const dim_vector dv = bnda.dims ();
 
@@ -620,18 +624,24 @@
   else
     {
       Array<octave_idx_type> retval (orig_dims);
-      std::memcpy (retval.fortran_vec (), data, len*sizeof (octave_idx_type));
-      // Delete the old copy and share the data instead to save memory.
-      delete [] data;
+
+      if (data)
+        {
+          std::memcpy (retval.fortran_vec (), data, len*sizeof (octave_idx_type));
+          // Delete the old copy and share the data instead to save memory.
+          delete [] data;
+        }
+
       data = retval.fortran_vec ();
       aowner = new Array<octave_idx_type> (retval);
+
       return retval;
     }
 }
 
 idx_vector::idx_mask_rep::idx_mask_rep (bool b)
-  : data (0), len (b ? 1 : 0), ext (0), lsti (-1), lste (-1),
-    aowner (0), orig_dims (len, len)
+  : idx_base_rep (), data (0), len (b ? 1 : 0), ext (0),
+    lsti (-1), lste (-1), aowner (0), orig_dims (len, len)
 {
   if (len != 0)
     {
@@ -644,8 +654,8 @@
 
 idx_vector::idx_mask_rep::idx_mask_rep (const Array<bool>& bnda,
                                         octave_idx_type nnz)
-  : data (0), len (nnz), ext (bnda.numel ()), lsti (-1), lste (-1),
-    aowner (0), orig_dims ()
+  : idx_base_rep (), data (0), len (nnz), ext (bnda.numel ()),
+    lsti (-1), lste (-1), aowner (0), orig_dims ()
 {
   if (nnz < 0)
     len = bnda.nnz ();
--- a/liboctave/array/idx-vector.h	Sat Apr 15 10:25:53 2017 -0700
+++ b/liboctave/array/idx-vector.h	Sat Apr 15 11:54:33 2017 -0400
@@ -72,6 +72,7 @@
   class OCTAVE_API idx_base_rep
   {
   public:
+
     idx_base_rep (void) : count (1), err (false) { }
 
     // No copying!
@@ -122,7 +123,8 @@
   class OCTAVE_API idx_colon_rep : public idx_base_rep
   {
   public:
-    idx_colon_rep (void) { }
+
+    idx_colon_rep (void) = default;
 
     idx_colon_rep (char c);
 
@@ -159,25 +161,25 @@
   class OCTAVE_API idx_range_rep : public idx_base_rep
   {
   public:
-    idx_range_rep (void)
-      : start(0), len(0), step(1) { }
+
+    idx_range_rep (void) = delete;
 
     idx_range_rep (octave_idx_type _start, octave_idx_type _len,
                    octave_idx_type _step, direct)
       : idx_base_rep (), start(_start), len(_len), step(_step) { }
 
+    // Zero-based constructor.
+    idx_range_rep (octave_idx_type _start, octave_idx_type _limit,
+                   octave_idx_type _step);
+
+    idx_range_rep (const Range&);
+
     // No copying!
 
     idx_range_rep (const idx_range_rep& idx) = delete;
 
     idx_range_rep& operator = (const idx_range_rep& idx) = delete;
 
-    // Zero-based constructor.
-    idx_range_rep (octave_idx_type _start, octave_idx_type _limit,
-                   octave_idx_type _step);
-
-    idx_range_rep (const Range&);
-
     octave_idx_type xelem (octave_idx_type i) const
     { return start + i * step; }
 
@@ -222,11 +224,11 @@
   class OCTAVE_API idx_scalar_rep : public idx_base_rep
   {
   public:
-    idx_scalar_rep (void)
-      : data (0) { }
+
+    idx_scalar_rep (void) = delete;
 
     idx_scalar_rep (octave_idx_type i, direct)
-      : data (i) { }
+      : idx_base_rep (), data (i) { }
 
     // No copying!
 
@@ -278,6 +280,7 @@
   class OCTAVE_API idx_vector_rep : public idx_base_rep
   {
   public:
+
     idx_vector_rep (void)
       : data (0), len (0), ext (0), aowner (0), orig_dims ()
     { }
@@ -285,7 +288,9 @@
     // Direct constructor.
     idx_vector_rep (octave_idx_type *_data, octave_idx_type _len,
                     octave_idx_type _ext, const dim_vector& od, direct)
-      : data (_data), len (_len), ext (_ext), aowner (0), orig_dims (od) { }
+      : idx_base_rep (), data (_data), len (_len), ext (_ext),
+        aowner (0), orig_dims (od)
+    { }
 
     // Zero-based constructor.
     idx_vector_rep (const Array<octave_idx_type>& inda);
@@ -357,16 +362,15 @@
   class OCTAVE_API idx_mask_rep : public idx_base_rep
   {
   public:
-    idx_mask_rep (void)
-      : data (0), len (0), ext (0), lsti (-1), lste (-1), aowner (0),
-        orig_dims ()
-    { }
+
+    idx_mask_rep (void) = delete;
 
     // Direct constructor.
     idx_mask_rep (bool *_data, octave_idx_type _len,
                   octave_idx_type _ext, const dim_vector& od, direct)
-      : data (_data), len (_len), ext (_ext), lsti (-1), lste (-1),
-        aowner (0), orig_dims (od) { }
+      : idx_base_rep (), data (_data), len (_len), ext (_ext),
+        lsti (-1), lste (-1), aowner (0), orig_dims (od)
+    { }
 
     idx_mask_rep (bool);