From 342cdb9589faf577ffe3bcbd4ce92c0ca1d15267 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 3 Jun 2019 05:41:58 -0400 Subject: [PATCH] Clear lgtm warning on unsafe functions --- validate.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/validate.h b/validate.h index 37ab53d5..a5352095 100644 --- a/validate.h +++ b/validate.h @@ -209,9 +209,15 @@ inline std::string TimeToString(const time_t& t) err = ::asctime_s(timeBuf, sizeof(timeBuf), &localTime); CRYPTOPP_ASSERT(err == 0); - std::string str(timeBuf); + std::string str(err == 0 ? timeBuf : ""); +#elif (_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE) + tm localTime = {}; + char timeBuf[64]; + char* timeString = ::asctime_r(::localtime_r(&t, &localTime), timeBuf); + std::string str(timeString ? timeString : ""); #else - std::string str(::asctime(::localtime(&t))); + char* timeString = ::asctime(::localtime(&t)); + std::string str(timeString ? timeString : ""); #endif // Cleanup whitespace