getfem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-commits] r4908 - in /trunk/getfem/src: getfem/getfem_mesh_im.h g


From: logari81
Subject: [Getfem-commits] r4908 - in /trunk/getfem/src: getfem/getfem_mesh_im.h getfem_mesh_im.cc
Date: Thu, 26 Mar 2015 12:08:10 -0000

Author: logari81
Date: Thu Mar 26 13:08:09 2015
New Revision: 4908

URL: http://svn.gna.org/viewcvs/getfem?rev=4908&view=rev
Log:
avoid returning dereferenced null pointer

Modified:
    trunk/getfem/src/getfem/getfem_mesh_im.h
    trunk/getfem/src/getfem_mesh_im.cc

Modified: trunk/getfem/src/getfem/getfem_mesh_im.h
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem/getfem_mesh_im.h?rev=4908&r1=4907&r2=4908&view=diff
==============================================================================
--- trunk/getfem/src/getfem/getfem_mesh_im.h    (original)
+++ trunk/getfem/src/getfem/getfem_mesh_im.h    Thu Mar 26 13:08:09 2015
@@ -1,10 +1,10 @@
 /* -*- c++ -*- (enables emacs c++ mode) */
 /*===========================================================================
- 
+
  Copyright (C) 2005-2012 Yves Renard
- 
+
  This file is a part of GETFEM++
- 
+
  Getfem++  is  free software;  you  can  redistribute  it  and/or modify it
  under  the  terms  of the  GNU  Lesser General Public License as published
  by  the  Free Software Foundation;  either version 3 of the License,  or
@@ -17,7 +17,7 @@
  You  should  have received a copy of the GNU Lesser General Public License
  along  with  this program;  if not, write to the Free Software Foundation,
  Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
- 
+
  As a special exception, you  may use  this file  as it is a part of a free
  software  library  without  restriction.  Specifically,  if   other  files
  instantiate  templates  or  use macros or inline functions from this file,
@@ -26,7 +26,7 @@
  to be covered  by the GNU Lesser General Public License.  This   exception
  does not  however  invalidate  any  other  reasons why the executable file
  might be covered by the GNU Lesser General Public License.
- 
+
 ===========================================================================*/
 
 /address@hidden getfem_mesh_im.h
@@ -45,8 +45,10 @@
 
   /// Describe an integration method linked to a mesh.
   class mesh_im : public context_dependencies {
+  private :
+    static mesh dummy_mesh;
+
   protected :
-    
     dal::dynamic_array<pintegration_method> ims;
     dal::bit_vector im_convexes;
     mesh *linked_mesh_;
@@ -69,55 +71,56 @@
      */
     inline const dal::bit_vector &convex_index(void) const
     { return im_convexes; }
-    
+
     /// Give a reference to the linked mesh of type mesh.
-    mesh &linked_mesh(void) const { return *linked_mesh_; }
+    mesh &linked_mesh(void) const
+    { return linked_mesh_ ? *linked_mesh_ : dummy_mesh; }
     /** Set the integration method of a convex.
 
-       @param cv the convex number
+        @param cv the convex number
 
-       @param pim the integration method, typically obtained with
-       @code getfem::int_method_descriptor("IM_SOMETHING(..)") 
-       @endcode
+        @param pim the integration method, typically obtained with
+        @code getfem::int_method_descriptor("IM_SOMETHING(..)")
+        @endcode
      */
     void set_integration_method(size_type cv, pintegration_method pim);
     /** Set the integration method on all the convexes of indexes in bv,
      *  which is of type dal::bit_vector.
      */
-    void set_integration_method(const dal::bit_vector &cvs, 
-                               pintegration_method pim);
+    void set_integration_method(const dal::bit_vector &cvs,
+                                pintegration_method pim);
     /** shortcut for
-       @code 
-       set_integration_method(linked_mesh().convex_index(),pim);
-       and set_auto_add(pim)
-       @endcode
+        @code
+        set_integration_method(linked_mesh().convex_index(),pim);
+        and set_auto_add(pim)
+        @endcode
     */
     void set_integration_method(pintegration_method ppi);
     /** Set an approximate integration method chosen to be exact for
-       polynomials of degree 'im_degree'.
+        polynomials of degree 'im_degree'.
     */
-    void set_integration_method(const dal::bit_vector &cvs, 
-                               dim_type im_degree);
-    
+    void set_integration_method(const dal::bit_vector &cvs,
+                                dim_type im_degree);
+
     /** Set an approximate integration method chosen to be exact for
-       polynomials of degree 'im_degree' on the whole mesh.
+        polynomials of degree 'im_degree' on the whole mesh.
     */
     void set_integration_method(dim_type im_degree);
-    
+
     /** return the integration method associated with an element (in
-       no integration is associated, the function will crash! use the
-       convex_index() of the mesh_im to check that a fem is
-       associated to a given convex) */
+        no integration is associated, the function will crash! use the
+        convex_index() of the mesh_im to check that a fem is
+        associated to a given convex) */
     virtual pintegration_method int_method_of_element(size_type cv) const
     { return  ims[cv]; }
     void clear(void);
-    
+
     size_type memsize() const {
-      return 
-       sizeof(mesh_im) +
-       ims.memsize() + im_convexes.memsize();
+      return
+        sizeof(mesh_im) +
+        ims.memsize() + im_convexes.memsize();
     }
-    
+
     void init_with_mesh(mesh &me);
     mesh_im(mesh &me);
     mesh_im(void);
@@ -133,16 +136,16 @@
     void read_from_file(const std::string &name);
     /** Write the mesh_im to a stream. */
     void write_to_file(std::ostream &ost) const;
-    /** Write the mesh_im to a file. 
+    /** Write the mesh_im to a file.
 
-       @param name the file name
+        @param name the file name
 
-       @param with_mesh if set, then the linked_mesh() will also be
-       saved to the file.
+        @param with_mesh if set, then the linked_mesh() will also be
+        saved to the file.
     */
     void write_to_file(const std::string &name, bool with_mesh=false) const;
   };
-  
+
 }  /* end of namespace getfem.                                             */
 
 

Modified: trunk/getfem/src/getfem_mesh_im.cc
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem_mesh_im.cc?rev=4908&r1=4907&r2=4908&view=diff
==============================================================================
--- trunk/getfem/src/getfem_mesh_im.cc  (original)
+++ trunk/getfem/src/getfem_mesh_im.cc  Thu Mar 26 13:08:09 2015
@@ -23,6 +23,8 @@
 
 
 namespace getfem {
+
+  mesh mesh_im::dummy_mesh = mesh();
   
   void mesh_im::update_from_context(void) const {
     for (dal::bv_visitor i(im_convexes); !i.finished(); ++i) {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]