Skip to content

Commit

Permalink
EAMxx: avoid nullptr when reading horiz remap sparse matrix entries
Browse files Browse the repository at this point in the history
A std vector of length 0 is not allocated, resulting in invalid memory
  • Loading branch information
bartgol committed Jun 10, 2024
1 parent 508ac99 commit da58272
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<gid_type> cols(nlweights);
std::vector<gid_type> rows(nlweights);
std::vector<Real> 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<gid_type> cols(nlweights+1,-1);
std::vector<gid_type> rows(nlweights+1,-1);
std::vector<Real> 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
Expand Down

0 comments on commit da58272

Please sign in to comment.