Commit a0323e63 authored by Lefebvre, Jordan's avatar Lefebvre, Jordan

Merge branch 'stack-smashing' into 'master'

Some compilers allow overrun of string format specifier. HysplitCDumpStream...

See merge request !91
parents b3857c82 43160d71
Pipeline #91335 passed with stages
in 21 minutes and 4 seconds
......@@ -149,7 +149,14 @@ bool HysplitCDumpStream<data_type>::write_to(const std::string &file) const
{
// force string to be only 4 characters
char cid[5];
sprintf(cid, "%4s", id.c_str());
if (id.size() > 4)
{
sprintf(cid, "%4s", id.substr(0, 4).c_str());
}
else
{
sprintf(cid, "%4s", id.c_str());
}
cid[4] = '\0'; // null terminate
id = cid;
}
......@@ -230,10 +237,17 @@ bool HysplitCDumpStream<data_type>::write_to(const std::string &file) const
std::string pol = mData->pollutant(i);
radix_tagged_line("pollutant=" << pol);
// force string to be only 4 characters
char cid[5];
sprintf(cid, "%4s", pol.c_str());
cid[4] = '\0';
std::string tmp = cid;
char icid[5];
if (pol.size() > 4)
{
sprintf(icid, "%4s", pol.substr(0, 4).c_str());
}
else
{
sprintf(icid, "%4s", pol.c_str());
}
icid[4] = '\0';
std::string tmp = icid;
fstr.writeString(tmp);
local_pols.push_back(tmp);
}
......@@ -307,6 +321,6 @@ bool HysplitCDumpStream<data_type>::write_to(const std::string &file) const
fstr.close();
result = true;
return result;
}
} // namespace radix
} // namespace radix
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment