Skip to content

Commit

Permalink
#1355 Terminate string
Browse files Browse the repository at this point in the history
  • Loading branch information
hsoh-u committed Nov 18, 2020
1 parent 646fdde commit f659654
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions met/src/libcode/vx_nc_obs/nc_obs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1289,12 +1289,14 @@ int write_nc_string_array (NcVar *ncVar, StringArray &strArray, const int str_le
for (int index=0; index<data_count; index++) {
int len, len2;
const string string_data= strArray[index];

processed_count++;
len = string_data.length();
len2 = strnlen(data_buf[buf_index], str_len);
if (len2 < len) len2 = len;
strncpy(data_buf[buf_index], string_data.c_str(), len);
// Make sure NULL terminated string
if(len < str_len) data_buf[buf_index][len] = bad_data_char;
//Cleanup garbage characters
for (int idx=len; idx<len2; idx++)
data_buf[buf_index][idx] = bad_data_char;

Expand Down

0 comments on commit f659654

Please sign in to comment.