From 108c38e0ee5f246fb2e8feb6bba9364e751fe7b6 Mon Sep 17 00:00:00 2001 From: MET Tools Test Account Date: Thu, 30 Jan 2025 21:37:35 +0000 Subject: [PATCH 1/4] Per #3054, fix PARUSR BUFRLIB error by solving the upstream reference to temporary memory returned by c_str(). Store a copy of the temporary variable name in a string rather than a pointer to temporary memory. Note that I checked all other calls to c_str() in pb2nc.cc and found these 2 instances to be only problematic ones. All others are used as arguments to functions for which a copy is made. --- src/tools/other/pb2nc/pb2nc.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tools/other/pb2nc/pb2nc.cc b/src/tools/other/pb2nc/pb2nc.cc index 94a7750bad..e682be2ada 100644 --- a/src/tools/other/pb2nc/pb2nc.cc +++ b/src/tools/other/pb2nc/pb2nc.cc @@ -59,6 +59,7 @@ // 019 07/21/23 Prestopnik, J. MET #2615 Add #include to compile // successfully using gcc12 // 020 08/26/24 Halley Gotway MET #2938 Silence center time warnings +// 021 01/30/25 Halley Gotway MET #3054 Fix PARUSR BUFRLIB error // //////////////////////////////////////////////////////////////////////// @@ -2444,10 +2445,9 @@ void process_pbfile_metadata(int i_pb) { int bufr_var_index = 0; bool has_prepbufr_vars = false; - const char * tmp_var_name; bufr_obs_name_arr.clear(); for (index=0; index Date: Thu, 30 Jan 2025 21:47:59 +0000 Subject: [PATCH 2/4] Unrelated to #3054, but discovered while investigating the dtcenter/METplus#2875 discussion, the PairBase::calc_obs_summary() function loops over map entries and attempts to update the mapped 'summary_val' value. However, the current version only updates it in a copy and not what's actually in the map. This changes how we loop over the map to actually udpate its contents. Note that the only impact is fixing a log file to accurately report the 'summary_val'. So this is really a logging bug. --- src/libcode/vx_statistics/pair_base.cc | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libcode/vx_statistics/pair_base.cc b/src/libcode/vx_statistics/pair_base.cc index a3b383f9fa..f9ed02e755 100644 --- a/src/libcode/vx_statistics/pair_base.cc +++ b/src/libcode/vx_statistics/pair_base.cc @@ -705,22 +705,21 @@ void PairBase::calc_obs_summary(){ if(!IsPointVx) return; // iterate over the keys in the unique station id map - for(int i=0; i " << "regex_apply failed to parse '" - << map_key[i] << "'\n\n"; + << v.first << "'\n\n"; exit(1); } - string msg_key = str_format("%s:%s:%s:%s", mat[1], mat[2], mat[3], - mat[4]).text(); + string msg_key = str_format("%s:%s:%s:%s", + mat[1], mat[2], + mat[3], mat[4]).text(); ob_val_t ob; @@ -754,21 +753,22 @@ void PairBase::calc_obs_summary(){ } // Store summarized value in the map - svt.summary_val = ob.val; - - typ_sa.add (svt.typ.c_str()); - sid_sa.add (svt.sid.c_str()); - lat_na.add (svt.lat); - lon_na.add (svt.lon); - x_na.add (svt.x); - y_na.add (svt.y); - wgt_na.add (svt.wgt); + v.second.summary_val = ob.val; + + typ_sa.add (v.second.typ.c_str()); + sid_sa.add (v.second.sid.c_str()); + lat_na.add (v.second.lat); + lon_na.add (v.second.lon); + x_na.add (v.second.x); + y_na.add (v.second.y); + wgt_na.add (v.second.wgt); vld_ta.add (ob.ut); - lvl_na.add (svt.lvl); - elv_na.add (svt.elv); + lvl_na.add (v.second.lvl); + elv_na.add (v.second.elv); o_na.add (ob.val); o_qc_sa.add (ob.qc.c_str()); - ClimoPntInfo cpi(svt.fcmn, svt.fcsd, svt.ocmn, svt.ocsd); + ClimoPntInfo cpi(v.second.fcmn, v.second.fcsd, + v.second.ocmn, v.second.ocsd); add_climo(ob.val, cpi); // Increment the number of pairs From d08ab28f8790f884331a0f408b97dde9993626d6 Mon Sep 17 00:00:00 2001 From: MET Tools Test Account Date: Fri, 31 Jan 2025 17:43:56 +0000 Subject: [PATCH 3/4] Per #3054, revert emplace_back() to its original push_back() to make the bugfix diffs as limited as possible. --- src/tools/other/pb2nc/pb2nc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/other/pb2nc/pb2nc.cc b/src/tools/other/pb2nc/pb2nc.cc index e682be2ada..3b896c8c31 100644 --- a/src/tools/other/pb2nc/pb2nc.cc +++ b/src/tools/other/pb2nc/pb2nc.cc @@ -2461,7 +2461,7 @@ void process_pbfile_metadata(int i_pb) { if (has_prepbufr_vars) { for (int vIdx=0; vIdx< prepbufr_derive_vars.n(); vIdx++) { const string tmp_var_name = prepbufr_derive_vars[vIdx].c_str(); - bufr_derive_cfgs.emplace_back(derive_var_cfg(tmp_var_name)); + bufr_derive_cfgs.push_back(derive_var_cfg(tmp_var_name)); if (do_all_vars || bufr_target_variables.has(tmp_var_name)) { // Set the variable index if requested bufr_obs_name_arr.add(tmp_var_name); From 5c98c120a31320dbf54b4e2c8f52ea811c20ff81 Mon Sep 17 00:00:00 2001 From: MET Tools Test Account Date: Fri, 31 Jan 2025 17:44:42 +0000 Subject: [PATCH 4/4] Per #3054, correct bugfix in PairBase::calc_obs_summary() in pair_base.cc --- src/libcode/vx_statistics/pair_base.cc | 36 ++++++++++++++------------ 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/libcode/vx_statistics/pair_base.cc b/src/libcode/vx_statistics/pair_base.cc index f9ed02e755..b68f391676 100644 --- a/src/libcode/vx_statistics/pair_base.cc +++ b/src/libcode/vx_statistics/pair_base.cc @@ -705,15 +705,17 @@ void PairBase::calc_obs_summary(){ if(!IsPointVx) return; // iterate over the keys in the unique station id map - for(auto &v : map_val) { + for(int i=0; i " << "regex_apply failed to parse '" - << v.first << "'\n\n"; + << map_key[i] << "'\n\n"; exit(1); } @@ -753,22 +755,22 @@ void PairBase::calc_obs_summary(){ } // Store summarized value in the map - v.second.summary_val = ob.val; - - typ_sa.add (v.second.typ.c_str()); - sid_sa.add (v.second.sid.c_str()); - lat_na.add (v.second.lat); - lon_na.add (v.second.lon); - x_na.add (v.second.x); - y_na.add (v.second.y); - wgt_na.add (v.second.wgt); + svt->summary_val = ob.val; + + typ_sa.add (svt->typ.c_str()); + sid_sa.add (svt->sid.c_str()); + lat_na.add (svt->lat); + lon_na.add (svt->lon); + x_na.add (svt->x); + y_na.add (svt->y); + wgt_na.add (svt->wgt); vld_ta.add (ob.ut); - lvl_na.add (v.second.lvl); - elv_na.add (v.second.elv); + lvl_na.add (svt->lvl); + elv_na.add (svt->elv); o_na.add (ob.val); o_qc_sa.add (ob.qc.c_str()); - ClimoPntInfo cpi(v.second.fcmn, v.second.fcsd, - v.second.ocmn, v.second.ocsd); + ClimoPntInfo cpi(svt->fcmn, svt->fcsd, + svt->ocmn, svt->ocsd); add_climo(ob.val, cpi); // Increment the number of pairs