Skip to content

Commit

Permalink
mktime called with properly initialized data
Browse files Browse the repository at this point in the history
  • Loading branch information
Fla3inH0tCheet0s authored and jinghaomiao committed Jun 24, 2019
1 parent 35cea78 commit 3053c41
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cyber/common/time_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ inline uint64_t GpsToUnixNanoseconds(uint64_t gps_nanoseconds) {
inline uint64_t StringToUnixSeconds(
const std::string& time_str,
const std::string& format_str = "%Y-%m-%d %H:%M:%S") {
struct tm* tmp_time = (struct tm*)malloc(sizeof(struct tm));
strptime(time_str.c_str(), format_str.c_str(), tmp_time);
time_t time = mktime(tmp_time);
free(tmp_time);
return (uint64_t)time;
tm tmp_time;
strptime(time_str.c_str(), format_str.c_str(), &tmp_time);
tmp_time.tm_isdst = -1;
time_t time = mktime(&tmp_time);
return static_cast<uint64_t>(time);
}

inline std::string UnixSecondsToString(
Expand Down

0 comments on commit 3053c41

Please sign in to comment.