From da19df122f7d0971dce1dfffae9da80c1a043bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 2 Mar 2012 17:42:26 +0100 Subject: [PATCH] Don't generate out-of-bounds ACTNUM references when inspecting ZCORN monotonicity. The C parsing rules (effectively) impose a "maximal munch" strategy. When iterating over the cell-nodes (i.e., ZCORN), the coordinate map integer division *must* apply to the iterators and not to a product of the form N*it. Enforce this interpretation by explicit parentheses. --- opm/core/utility/cpgpreprocess/preprocess.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/core/utility/cpgpreprocess/preprocess.c b/opm/core/utility/cpgpreprocess/preprocess.c index 7ecbe597..48daf419 100644 --- a/opm/core/utility/cpgpreprocess/preprocess.c +++ b/opm/core/utility/cpgpreprocess/preprocess.c @@ -457,8 +457,8 @@ void process_grdecl(const struct grdecl *in, double z1 = sign*in->zcorn[i+2*nx*(j+2*ny*(k))]; double z2 = sign*in->zcorn[i+2*nx*(j+2*ny*(k+1))]; - int c1 = i/2 + nx*(j/2 + ny*k/2); - int c2 = i/2 + nx*(j/2 + ny*(k+1)/2); + int c1 = i/2 + nx*(j/2 + ny*(k/2)); + int c2 = i/2 + nx*(j/2 + ny*((k+1)/2)); if (in->actnum[c1] && in->actnum[c2] && (z2 < z1)){ fprintf(stderr, "\nZCORN should be strictly nondecreasing along pillars!\n");