]> git.sur5r.net Git - i3/i3status/commitdiff
Avoid use of uninitialized variable in print_battery_info
authorAlexander Monakov <amonakov@ispras.ru>
Thu, 18 Dec 2014 15:23:25 +0000 (18:23 +0300)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 22 Dec 2014 08:19:40 +0000 (09:19 +0100)
The boolean flag 'watt_as_unit' may be used without being initialized if the
configured battery path does not contain expected statistics (for example if
it is misconfigured and points to AC adapter info or simply an unrelated file).

Even though it does not cause ill effects, it causes a warning (true positive)
when running i3status under Valgrind.  Initialize the variable to make code
well-defined.

src/print_battery_info.c

index 28b94ec25ae26b7eaac47c7efbec9d794ede8a5d..0df9b729be8e01039c2c060d3210cfa43672bd83 100644 (file)
@@ -44,7 +44,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
         char consumptionbuf[256];
         const char *walk, *last;
         char *outwalk = buffer;
-        bool watt_as_unit;
+        bool watt_as_unit = false;
         bool colorful_output = false;
         int full_design = -1,
             remaining = -1,