]> www.ginac.de Git - ginac.git/commitdiff
fixed possible memory corruption in index contraction
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 5 Sep 2002 20:16:59 +0000 (20:16 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 5 Sep 2002 20:16:59 +0000 (20:16 +0000)
ginac/tensor.cpp

index 0c36a68002423d712f4d8afa5ec903716ffba7e7..b7ae299838b3bb73003ac38e382ff615a31d5804 100644 (file)
@@ -348,8 +348,8 @@ again:
                                try {
                                        // minimal_dim() throws an exception when index dimensions are not comparable
                                        ex min_dim = self_idx->minimal_dim(other_idx);
-                                       *self = _ex1;
                                        *other = other->subs(other_idx == free_idx->replace_dim(min_dim));
+                                       *self = _ex1; // *other is assigned first because assigning *self invalidates free_idx
                                        return true;
                                } catch (std::exception &e) {
                                        return false;
@@ -459,9 +459,10 @@ again:
                        if (is_dummy_pair(*self_idx, other_idx)) {
 
                                // Contraction found, remove metric tensor and substitute
-                               // index in second object
-                               *self = (static_cast<const spinidx *>(self_idx)->is_covariant() ? sign : -sign);
+                               // index in second object (assign *self last because this
+                               // invalidates free_idx)
                                *other = other->subs(other_idx == *free_idx);
+                               *self = (static_cast<const spinidx *>(self_idx)->is_covariant() ? sign : -sign);
                                return true;
                        }
                }