From da58272d4a232b0fc620a07f7d25606cd881db60 Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Mon, 10 Jun 2024 15:45:49 -0600 Subject: [PATCH] EAMxx: avoid nullptr when reading horiz remap sparse matrix entries A std vector of length 0 is not allocated, resulting in invalid memory --- .../src/share/grid/remap/horiz_interp_remapper_data.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/eamxx/src/share/grid/remap/horiz_interp_remapper_data.cpp b/components/eamxx/src/share/grid/remap/horiz_interp_remapper_data.cpp index b26501a499b..2f08e5a2be5 100644 --- a/components/eamxx/src/share/grid/remap/horiz_interp_remapper_data.cpp +++ b/components/eamxx/src/share/grid/remap/horiz_interp_remapper_data.cpp @@ -49,9 +49,11 @@ get_my_triplets (const std::string& map_file) const int nlweights = scorpio::get_dimlen_local(map_file,"n_s"); // 1.1 Read a chunk of triplets col indices - std::vector cols(nlweights); - std::vector rows(nlweights); - std::vector S(nlweights); + // NOTE: add 1 so that we don't pass nullptr to scorpio read routines (which would trigger + // a runtime error). Don't worry though: we never access the last entry of these vectors + std::vector cols(nlweights+1,-1); + std::vector rows(nlweights+1,-1); + std::vector S(nlweights+1,0); // Figure out if we are reading the right map, that is: // - n_a or n_b matches the fine grid ncols