From e9bd0d92d3573c4bcc24397914481cf9ed1aa6d1 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Thu, 5 Sep 2002 20:16:59 +0000 Subject: [PATCH] fixed possible memory corruption in index contraction --- ginac/tensor.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ginac/tensor.cpp b/ginac/tensor.cpp index 0c36a680..b7ae2998 100644 --- a/ginac/tensor.cpp +++ b/ginac/tensor.cpp @@ -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(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(self_idx)->is_covariant() ? sign : -sign); return true; } } -- 2.45.1