From 04c9b66107760d72e98c849c7ca5aae616dc0f20 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Wed, 16 Nov 2016 17:20:24 +0100 Subject: [PATCH] fix some valgrind errors in the EQUIL code this fixes some valgrind errors while doing the twophase capability for flow_ebos: In all previously tested cases, these errors were probably non-fatal because the memory illegally accessed here is likely to be allocated (but after this function was finished it contained garbage). note that I'm not completely sure if this patch is semantically correct, so I'd appreciate some input who understands it. (what is "z"?) --- opm/core/simulator/initState_impl.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/opm/core/simulator/initState_impl.hpp b/opm/core/simulator/initState_impl.hpp index fd4cbb017..6b05107f4 100644 --- a/opm/core/simulator/initState_impl.hpp +++ b/opm/core/simulator/initState_impl.hpp @@ -896,12 +896,15 @@ namespace Opm for (int col = 0; col < np; ++col) { z[0] += A_a[0 + np*col]*s[col]; z[1] += A_l[1 + np*col]*s[col]; - z[2] += A_v[2 + np*col]*s[col]; + if (np > 2) + z[2] += A_v[2 + np*col]*s[col]; } - double ztmp = z[2]; - z[2] += z[1]*rs[c]; - z[1] += ztmp*rv[c]; + if (np > 2) { + double ztmp = z[2]; + z[2] += z[1]*rs[c]; + z[1] += ztmp*rv[c]; + } } }