Skip to content

Commit b614bd3

Browse files
committed
Durations don't always zero init
In a couple of places I assumed that durations and time_points always zero-initialised. This is incorrect - they act as if they were their representation, so integer durations only zero-init when static. You can zero init (like integers) by having `{}` initialisation.
1 parent 58388b7 commit b614bd3

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

drivers/Ticker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class TickerBase : public TimerEvent, private NonCopyable<TickerBase> {
149149
void attach_absolute(Callback<void()> func, TickerDataClock::time_point abs_time);
150150

151151
void handler() override;
152-
std::chrono::microseconds _delay; /**< Time delay (in microseconds) for resetting the multishot callback. */
152+
std::chrono::microseconds _delay{0}; /**< Time delay (in microseconds) for resetting the multishot callback. */
153153
Callback<void()> _function; /**< Callback. */
154154
bool _lock_deepsleep; /**< Flag which indicates if deep sleep should be disabled. */
155155
#endif

drivers/Timer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class TimerBase : private NonCopyable<TimerBase> {
111111
TimerBase(const ticker_data_t *data, bool lock_deepsleep);
112112
~TimerBase();
113113
std::chrono::microseconds slicetime() const;
114-
TickerDataClock::time_point _start; // the start time of the latest slice
115-
std::chrono::microseconds _time; // any accumulated time from previous slices
114+
TickerDataClock::time_point _start{}; // the start time of the latest slice
115+
std::chrono::microseconds _time{}; // any accumulated time from previous slices
116116
TickerDataClock _ticker_data;
117117
bool _lock_deepsleep; // flag that indicates if deep sleep should be disabled
118118
bool _running = false; // whether the timer is running

drivers/source/Timer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ microseconds TimerBase::elapsed_time() const
100100
microseconds TimerBase::slicetime() const
101101
{
102102
CriticalSectionLock lock;
103-
microseconds ret;
103+
microseconds ret = 0us;
104104
if (_running) {
105105
ret = _ticker_data.now() - _start;
106106
}

0 commit comments

Comments
 (0)