Skip to content
Snippets Groups Projects
Commit 6f2b1868 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

KVListAppendNamelist: replace snprintf() my memcpy()

parent 955e4068
No related branches found
No related tags found
No related merge requests found
Pipeline #8633 passed
......@@ -6,6 +6,10 @@
2021-06-14 Uwe Schulzweida
* KVListAppendNamelist: replace snprintf() my memcpy()
2021-06-13 Uwe Schulzweida
* New median operators - ensmedian, fldmedian, mermedian, zonmedian, gridboxmedian
* New skewness operators - ensskew, fldskew, merskew, zonskew, gridboxskew
* New kurtosis operators - enskurt, fldkurt, merkurt, zonkurt, gridboxkurt
......
......@@ -153,7 +153,6 @@ PMList::getKVListVentry(const std::vector<std::string> &entry)
static void
KVListAppendNamelist(KVList &kvlist, const char *key, const char *buffer, NamelistToken *t, int nvalues, bool cdocmor)
{
char vbuf[4096];
std::vector<char> value;
KeyValues kv;
kv.key = key;
......@@ -166,16 +165,8 @@ KVListAppendNamelist(KVList &kvlist, const char *key, const char *buffer, Nameli
/** CMOR_MAX_STRING cannot be used **/
if (cdocmor && len > 1024) cdo_abort("A string value is larger than the maximum size allowed by CMOR (1024 signs).");
value.resize(len + 1);
// printf(" value[%d] >%.*s<\n", i, (int)len, buffer+t[i].start);
auto pval = buffer + t[i].start;
if (len < sizeof(vbuf)) // snprintf seems to call strlen(pval)
{
memcpy(vbuf, buffer + t[i].start, len);
vbuf[len] = 0;
pval = vbuf;
}
if (value.size() < (len + 1) ) value.resize(len + 1);
const auto pval = buffer + t[i].start;
if (cdocmor && strcmp(key, "code") == 0 && !strstr(pval, ","))
{
......@@ -184,14 +175,12 @@ KVListAppendNamelist(KVList &kvlist, const char *key, const char *buffer, Nameli
if (code > 0 && code < 1000)
snprintf(value.data(), 4, "%03ld", code);
else
{
cdo_warning("In parsing a line of a file:\n "
"Codes could not be transformed into the code format (three digit integer). Codes wont be used.");
}
cdo_warning("In parsing a line of a file:\n "
"Codes could not be transformed into the code format (three digit integer). Codes wont be used.");
}
else
{
snprintf(value.data(), len + 1, "%.*s", (int) len, pval);
memcpy(value.data(), pval, len);
value[len] = 0;
}
kv.values[i] = value.data();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment