Commit 43598c63 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Fix uninitialized tm in data_obs

parent e36e60d0
......@@ -118,16 +118,19 @@ int data_obs::set_time(int year, int mon, int day, int hour, int min, int sec,
********************************************************************************/
int data_obs::set_time(struct timespec* time) {
struct tm* tm;
gmtime_r(&time->tv_sec,tm);
year = tm->tm_year + 1900;
mon = tm->tm_mon + 1;
day = tm->tm_mday;
hour = tm->tm_hour;
min = tm->tm_min;
sec = tm->tm_sec;
// Initialize tm
//TODO Make t a class-variable to avoid repeated allocation
struct tm t = {0};
// Use gmtime_r for thread-safety
gmtime_r(&time->tv_sec,&t);
year = t.tm_year + 1900;
mon = t.tm_mon + 1;
day = t.tm_mday;
hour = t.tm_hour;
min = t.tm_min;
sec = t.tm_sec;
msec = (int) (time->tv_nsec / 1e6);
return (0);
......
Supports Markdown
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