Skip to content

Commit

Permalink
Fix segfault in get_global_index1F
Browse files Browse the repository at this point in the history
Co-authored-by: Zohar Malamant <zom@equinor.com>
  • Loading branch information
eivindjahren and pinkwah committed Apr 23, 2024
1 parent 04c1a99 commit 29adfa4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/resdata/rd_grid.cpp
Expand Up @@ -4752,6 +4752,9 @@ int rd_grid_get_global_index1A(const rd_grid_type *rd_grid, int active_index) {

int rd_grid_get_global_index1F(const rd_grid_type *rd_grid,
int active_fracture_index) {
if (rd_grid->inv_fracture_index_map == NULL ||
active_fracture_index >= rd_grid->total_active_fracture)
return -1;
return rd_grid->inv_fracture_index_map[active_fracture_index];
}

Expand Down
7 changes: 6 additions & 1 deletion python/resdata/grid/rd_grid.py
Expand Up @@ -581,8 +581,13 @@ def get_active_fracture_index(self, ijk=None, global_index=None):
def get_global_index1F(self, active_fracture_index):
"""
Will return the global index corresponding to active fracture index.
Returns None if there is no active_fracture with that index
"""
return self._get_global_index1F(active_fracture_index)
result = self._get_global_index1F(active_fracture_index)
if result == -1:
return None
return result

def cell_invalid(self, ijk=None, global_index=None, active_index=None):
"""
Expand Down
1 change: 1 addition & 0 deletions python/tests/rd_tests/test_grid.py
Expand Up @@ -222,6 +222,7 @@ def test_posXYEdge(self):

def test_dims(self):
grid = GridGen.createRectangular((10, 20, 30), (1, 1, 1))
self.assertEqual(grid.get_global_index1F(0), None)
self.assertEqual(grid.getNX(), 10)
self.assertEqual(grid.getNY(), 20)
self.assertEqual(grid.getNZ(), 30)
Expand Down

0 comments on commit 29adfa4

Please sign in to comment.