Commit be4c75a7 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

src: Use gmtime_r instead of gmtime

parent 7b9a8acc
...@@ -138,9 +138,14 @@ std::string percentDecode ...@@ -138,9 +138,14 @@ std::string percentDecode
std::string http_date(time_t t) std::string http_date(time_t t)
{ {
char buf[32]; char buf[32];
tm* tms = gmtime(&t); // returned struct is statically allocated. tm tms;
size_t r = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", tms);
return std::string(&buf[0], &buf[r]); 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) time_t parse_http_date(const std::string& s)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment