Commit 35830f15 authored by Ronan's avatar Ronan

fix(DbSession): avoid two calls to snprintf to build current timestamp buffer

parent 11549618
Pipeline #311 failed with stage
in 0 seconds
......@@ -134,16 +134,11 @@ string DbSession::currentTimestamp () const {
// Ugly hack but Sqlite3 does not allow table alteration where we add a date column using a default value
// of CURRENT_TIMESTAMP.
const tm &now = Utils::getTimeTAsTm(std::time(nullptr));
int n = snprintf(
0,
0,
"'%d-%02d-%02d %02d:%02d:%02d'",
now.tm_year + 1900, now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec
);
char buffer[n + 1];
char buffer[128];
snprintf(
buffer,
(size_t)n+1,
sizeof buffer,
"'%d-%02d-%02d %02d:%02d:%02d'",
now.tm_year + 1900, now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec
);
......
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