From 3b1faf9c91d1fd7d1bb26b744bf0a84c631806f0 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 12 Sep 2017 17:12:57 +0200 Subject: Fix incorrect usage of gmtime_r in timestamp decoder --- src/TimestampDecoder.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/TimestampDecoder.h') diff --git a/src/TimestampDecoder.h b/src/TimestampDecoder.h index c835430..e0dee2a 100644 --- a/src/TimestampDecoder.h +++ b/src/TimestampDecoder.h @@ -46,7 +46,9 @@ struct frame_timestamp bool timestamp_valid; bool timestamp_refresh; - struct frame_timestamp operator=(const struct frame_timestamp &rhs) + frame_timestamp() = default; + frame_timestamp(const frame_timestamp& other) = default; + frame_timestamp operator=(const frame_timestamp &rhs) { if (this != &rhs) { this->timestamp_sec = rhs.timestamp_sec; @@ -59,7 +61,7 @@ struct frame_timestamp return *this; } - struct frame_timestamp& operator+=(const double& diff) + frame_timestamp& operator+=(const double& diff) { double offset_pps, offset_secs; offset_pps = modf(diff, &offset_secs); @@ -75,9 +77,9 @@ struct frame_timestamp return *this; } - const struct frame_timestamp operator+(const double diff) + const frame_timestamp operator+(const double diff) { - struct frame_timestamp ts = *this; + frame_timestamp ts = *this; ts += diff; return ts; } @@ -89,7 +91,7 @@ struct frame_timestamp void print(const char* t) { fprintf(stderr, - "%s \n", + "%s \n", t, this->timestamp_valid ? "valid" : "invalid", this->timestamp_sec, pps_offset(), this->fct); @@ -122,8 +124,12 @@ class TimestampDecoder : public RemoteControllable latestFCT = 0; enableDecode = false; full_timestamp_received = false; - bzero(&temp_time, sizeof(temp_time)); - gmtime_r(0, &temp_time); + + // Properly initialise temp_time + memset(&temp_time, 0, sizeof(temp_time)); + const time_t timep = 0; + gmtime_r(&timep, &temp_time); + offset_changed = false; RC_ADD_PARAMETER(offset, "TIST offset [s]"); @@ -135,7 +141,7 @@ class TimestampDecoder : public RemoteControllable }; /* Calculate the timestamp for the current frame. */ - void calculateTimestamp(struct frame_timestamp& ts); + void calculateTimestamp(frame_timestamp& ts); /* Update timestamp data from ETI */ void updateTimestampEti( @@ -206,7 +212,7 @@ class TimestampDecoder : public RemoteControllable * synchronise two modulators if only one uses (for instance) the * FIRFilter (1 stage pipeline) */ - std::queue > queue_timestamps; + std::queue > queue_timestamps; }; -- cgit v1.2.3