Skip to content
Snippets Groups Projects
Commit 2acf0dac authored by Sébastien Blin's avatar Sébastien Blin Committed by Andreas Traczyk
Browse files

databasehelper: protect stoull call


stoull() can throw an exception here, must be placed in a try/catch
block

Change-Id: Ie8ae8262858d0307ad72ba734b72f56971346c37
Reviewed-by: default avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent e2d3703d
Branches
Tags
No related merge requests found
......@@ -430,7 +430,17 @@ uint64_t
getLastTimestamp(Database& db)
{
auto timestamps = db.select("MAX(timestamp)", "interactions", "1=1", {}).payloads;
return timestamps.empty() ? std::time(nullptr) : std::stoull(timestamps[0]);
auto result = std::time(nullptr);
try {
if (!timestamps.empty() && !timestamps[0].empty()) {
result = std::stoull(timestamps[0]);
}
} catch (const std::out_of_range& e) {
qDebug() << "database::getLastTimestamp, stoull throws an out_of_range exception: " << e.what();
} catch (const std::invalid_argument& e) {
qDebug() << "database::getLastTimestamp, stoull throws an invalid_argument exception: " << e.what();
}
return result;
}
} // namespace database
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment