WSL/SLF GitLab Repository

Skip to content

Fix read-in of a NetCDF dates list

Michael Reisecker requested to merge fix/strmaxlen into master

I'm trying to read dates from a NetCDF file. Presumably this worked for some kind of Null-terminated data in some files? For me and simple date strings it didn't and behaved like this minimal example:

char *data = (char*)calloc(length, sizeof(char));
data[0] = 'a'; data[1] = 'b'; data[2] = 'c';
std::string res(&data[1]);

(Giving "bc", or in the case of MeteoIO the first string would be all dates after each other, the next one all dates again but truncated by length strMaxLen, etc.)

Here is how ncdump displays the strings:

dimensions:
        (...)
        DateStrLen = 19 ;
        (...)

data:

 Times =
  "2022-09-18_06:00:00",
  "2022-09-18_07:00:00",
  (...)
  "2022-09-19_02:00:00",
  "2022-09-19_03:00:00" ;

So, is strMaxLen really just an upper limit, and with this fix do we need to take care of string termination before reaching this length afterwards?

Merge request reports