From d7d0fbcae4ed581de9734400e21fa99542cd59a4 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Wed, 11 Jan 2017 15:01:38 +0100 Subject: [PATCH] fix(battery): Safety check Make sure returned label is valid before access. Refs #318 --- src/modules/battery.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 87613ce8..a38cba49 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -198,11 +198,13 @@ namespace modules { } }(); - label->reset_tokens(); - label->replace_token("%percentage%", to_string(m_percentage) + "%"); + if (label) { + label->reset_tokens(); + label->replace_token("%percentage%", to_string(m_percentage) + "%"); - if (m_state != battery_module::state::FULL && !m_timeformat.empty()) { - label->replace_token("%time%", current_time()); + if (m_state != battery_module::state::FULL && !m_timeformat.empty()) { + label->replace_token("%time%", current_time()); + } } return true;