From e8f42d5abc360c011b9a455a596e13b101d63f58 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 16 Sep 2021 20:40:55 -0600 Subject: [PATCH] #1922 Removed trailing spaces based on the string lenth than buffer length --- met/src/tools/other/ioda2nc/ioda2nc.cc | 31 +++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/met/src/tools/other/ioda2nc/ioda2nc.cc b/met/src/tools/other/ioda2nc/ioda2nc.cc index 04c58c0909..3b0da9288c 100644 --- a/met/src/tools/other/ioda2nc/ioda2nc.cc +++ b/met/src/tools/other/ioda2nc/ioda2nc.cc @@ -59,6 +59,8 @@ static const char * DEF_CONFIG_NAME = "MET_BASE/config/IODA2NCConfig_default"; static const char *program_name = "ioda2nc"; +static const int REJECT_DEBUG_LEVEL = 9; + //////////////////////////////////////////////////////////////////////// // @@ -662,7 +664,6 @@ void process_ioda_file(int i_pb) { if(has_msg_type) { int buf_len = sizeof(modified_hdr_typ); m_strncpy(hdr_typ, hdr_msg_types+(i_read*nstring), nstring, method_name, "hdr_typ"); - hdr_typ[nstring] = 0; // Null terminate the message type string cleanup_hdr_buf(hdr_typ, nstring); @@ -692,7 +693,6 @@ void process_ioda_file(int i_pb) { if(has_station_id) { char tmp_sid[nstring+1]; m_strncpy(tmp_sid, hdr_station_ids+(i_read*nstring), nstring, method_name, "tmp_sid"); - tmp_sid[nstring] = 0; cleanup_hdr_buf(tmp_sid, nstring); hdr_sid = tmp_sid; } @@ -990,7 +990,9 @@ static void cleanup_hdr_buf(char *hdr_buf, int buf_len) { int i; hdr_buf[buf_len] = '\0'; // Change the trailing blank space to a null - for(i=buf_len-1; i>=0; i--) { + int str_len = m_strlen(hdr_buf); + if (buf_len <= str_len) str_len = buf_len; + for(i=str_len-1; i>=0; i--) { if(' ' == hdr_buf[i]) { hdr_buf[i] = '\0'; if(i > 0 && ' ' != hdr_buf[i-1]) break; @@ -1001,10 +1003,12 @@ static void cleanup_hdr_buf(char *hdr_buf, int buf_len) { //////////////////////////////////////////////////////////////////////// bool keep_message_type(const char *mt_str) { - bool keep = false; + bool keep = conf_info.message_type.n_elements() == 0 || + conf_info.message_type.has(mt_str, false); - keep = conf_info.message_type.n_elements() == 0 || - conf_info.message_type.has(mt_str, false); + if(!keep && mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) { + mlog << Debug(REJECT_DEBUG_LEVEL) << "The message type [" << mt_str << "] is rejected\n"; + } return(keep); } @@ -1013,8 +1017,14 @@ bool keep_message_type(const char *mt_str) { bool keep_station_id(const char *sid_str) { - return(conf_info.station_id.n_elements() == 0 || - conf_info.station_id.has(sid_str, false)); + bool keep = (conf_info.station_id.n_elements() == 0 || + conf_info.station_id.has(sid_str, false)); + + if(!keep && mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) { + mlog << Debug(REJECT_DEBUG_LEVEL) << "The station ID [" << sid_str << "] is rejected\n"; + } + + return(keep); } //////////////////////////////////////////////////////////////////////// @@ -1036,6 +1046,11 @@ bool keep_valid_time(const unixtime ut, if(ut > max_ut) keep = false; } + if(!keep && mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) { + mlog << Debug(REJECT_DEBUG_LEVEL) << "The valid_time [" << ut << ", " + << unix_to_yyyymmdd_hhmmss(ut) << "] is rejected\n"; + } + return(keep); }