Fix for platforms which returns 'unknown' instead of value/unit pair.
http://bugzilla.redhat.com/show_bug.cgi?id=770289
---
 measurement/acpi.cpp |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/measurement/acpi.cpp b/measurement/acpi.cpp
index e507f1a..b9b10fb 100644
--- a/measurement/acpi.cpp
+++ b/measurement/acpi.cpp
@@ -108,8 +108,13 @@ void acpi_power_meter::measure(void)
                        while (*c == ' ') c++;
                        _capacity = strtoull(c, NULL, 10);
                        c = strchr(c, ' ');
-                       c++;
-                       strcpy(capacity_units, c);
+                       if (c) {
+                               c++;
+                               strcpy(capacity_units, c);
+                       } else {
+                               _capacity = 0;
+                               strcpy(capacity_units, "Unknown");
+                       }
                }
                if (strstr(line, "present voltage:")) {
                        c = strchr(line, ':');
@@ -117,8 +122,13 @@ void acpi_power_meter::measure(void)
                        while (*c == ' ') c++;
                        _voltage = strtoull(c, NULL, 10);
                        c = strchr(c, ' ');
-                       c++;
-                       strcpy(voltage_units, c);
+                       if (c) {
+                               c++;
+                               strcpy(voltage_units, c);
+                       } else {
+                               _voltage = 0;
+                               strcpy(voltage_units, "Unknown");
+                       }
                }
        }
        file.close();
-- 
1.7.7.5

_______________________________________________
Power mailing list
Power@bughost.org
https://bughost.org/mailman/listinfo/power

Reply via email to