From 75dae3fb96fc0dcd2cd13a64e98165c7f316419b Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 11 Feb 2023 14:05:01 -0800 Subject: [PATCH] replace localtime with _s/_r variant cppcheck warns on localtime which is not necessarily threadsafe. Signed-off-by: Rosen Penev --- src/crwimage_int.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 10746418..69b1a3f3 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -741,7 +741,12 @@ void CrwMap::decode0x180e(const CiffComponent& ciffComponent, const CrwMapping* ULongValue v; v.read(ciffComponent.pData(), 8, byteOrder); time_t t = v.value_.at(0); - auto tm = std::localtime(&t); + struct tm r; +#ifdef _WIN32 + auto tm = localtime_s(&r, &t) ? nullptr : &r; +#else + auto tm = localtime_r(&t, &r); +#endif if (tm) { const size_t m = 20; char s[m];