Skip to content

Commit 488b9fe

Browse files
authored
Replace non-reentrant localtime with localtime_r, zero-init struct tm, check return value
1 parent 3b07c49 commit 488b9fe

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

source/databaseConnection.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ void DatabaseConnection::printResults(const std::vector<PriceData>& results) con
6161
for (const auto& data : results) {
6262
// Convert timestamp back to string for display
6363
auto time_t = std::chrono::system_clock::to_time_t(data.timestamp);
64-
auto tm = *std::localtime(&time_t);
64+
struct tm tm = {};
65+
if (localtime_r(&time_t, &tm) == nullptr) {
66+
std::cerr << "Error: failed to convert timestamp" << std::endl;
67+
continue;
68+
}
6569
std::stringstream ss;
6670
ss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S");
6771

0 commit comments

Comments
 (0)