-
Notifications
You must be signed in to change notification settings - Fork 4
Replace non-reentrant localtime with localtime_r in databaseConnection.cpp
#13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,11 @@ void DatabaseConnection::printResults(const std::vector<PriceData>& results) con | |
| for (const auto& data : results) { | ||
| // Convert timestamp back to string for display | ||
| auto time_t = std::chrono::system_clock::to_time_t(data.timestamp); | ||
| auto tm = *std::localtime(&time_t); | ||
| struct tm tm = {}; | ||
| if (localtime_r(&time_t, &tm) == nullptr) { | ||
| std::cerr << "Error: failed to convert timestamp" << std::endl; | ||
| continue; | ||
| } | ||
|
Comment on lines
+65
to
+68
|
||
| std::stringstream ss; | ||
| ss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S"); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
localtime_ris a POSIX API and is not available under MSVC/Windows builds. Since the project’s CMakeLists explicitly supports MSVC, this change can break Windows compilation. Consider adding a small platform abstraction (e.g.,#if defined(_WIN32)uselocaltime_s(&tm, &time_t); otherwiselocaltime_r) and qualifying the call (::localtime_r) with the appropriate<ctime>/<time.h>include so the declaration is guaranteed to be visible.