From be4c75a7e995f1fd25c6d602aeb45893d0e7bf62 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 14 May 2014 21:23:21 +0900 Subject: [PATCH] src: Use gmtime_r instead of gmtime --- src/util.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/util.cc b/src/util.cc index 9e386fcc..e5440836 100644 --- a/src/util.cc +++ b/src/util.cc @@ -138,9 +138,14 @@ std::string percentDecode std::string http_date(time_t t) { char buf[32]; - tm* tms = gmtime(&t); // returned struct is statically allocated. - size_t r = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", tms); - return std::string(&buf[0], &buf[r]); + tm tms; + + if(gmtime_r(&t, &tms) == nullptr) { + return ""; + } + + auto rv = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", &tms); + return std::string(&buf[0], &buf[rv]); } time_t parse_http_date(const std::string& s)