getfem-commits
[Top][All Lists]
Advanced

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

[Getfem-commits] (no subject)


From: Andriy Andreykiv
Subject: [Getfem-commits] (no subject)
Date: Thu, 6 Jun 2019 08:27:00 -0400 (EDT)

branch: csr_matrix_and_memory_fixes
commit f222414c84e8294857a5f1e7975b2ef06a024a01
Author: Andriy.Andreykiv <address@hidden>
Date:   Thu Jun 6 14:25:09 2019 +0200

    preventing container out of bound access
---
 src/getfem/getfem_accumulated_distro.h |  4 ++--
 src/gmm/gmm_vector.h                   | 34 ++++++++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/getfem/getfem_accumulated_distro.h 
b/src/getfem/getfem_accumulated_distro.h
index f323809..ebf8226 100644
--- a/src/getfem/getfem_accumulated_distro.h
+++ b/src/getfem/getfem_accumulated_distro.h
@@ -213,8 +213,8 @@ namespace detail {
           }
         )
         //erase every second item , as it was already added
-        for (auto it = begin(to_add);
-             next(it) < end(to_add);
+        for (auto it = begin(to_add), ite = end(to_add);
+             it != end(to_add) && next(it) != end(to_add);
              it = to_add.erase(next(it)));
       }
     }
diff --git a/src/gmm/gmm_vector.h b/src/gmm/gmm_vector.h
index dbc4029..19b4a27 100644
--- a/src/gmm/gmm_vector.h
+++ b/src/gmm/gmm_vector.h
@@ -1212,15 +1212,33 @@ namespace gmm {
 
     v2.base_resize(nbc);
     it3 = v2.begin() + old_nbc;
-    it2 = v2.end(); ite2 = v2.begin();
-    it1 = vect_end(v1); ite1 = vect_const_begin(v1);
-    while (it1 != ite1 && it3 != ite2) {
-      --it3; --it1; --it2;
-      if (it3->c > it1.index()) { *it2 = *it3; ++it1; }
-      else if (it3->c == it1.index()) { *it2=*it3; it2->e+=*it1; }
-      else { it2->c = it1.index(); it2->e = *it1; ++it3; }
+    it2 = v2.end();
+    ite2 = v2.begin();
+    it1 = vect_end(v1);
+    ite1 = vect_const_begin(v1);
+    while (it1 != ite1 && it2 != ite2 && it3 != ite2){
+      --it3;
+      --it1;
+      --it2;
+      if (it3->c > it1.index()) {
+        *it2 = *it3;
+        ++it1;
+      }
+      else if (it3->c == it1.index()) {
+        *it2=*it3;
+        it2->e+=*it1;
+      }
+      else {
+        it2->c = it1.index();
+        it2->e = *it1; ++it3;
+      }
+    }
+    while (it1 != ite1 && it2 != ite2) {
+      --it1;
+      --it2;
+      it2->c = it1.index();
+      it2->e = *it1;
     }
-    while (it1 != ite1) { --it1; --it2; it2->c = it1.index(); it2->e = *it1; }
   }
 
   template <typename V, typename T> void copy(const V &v1, rsvector<T> &v2) {



reply via email to

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