[gnome-battery-bench] SystemInfo: strip sysfs strings better



commit 5b4477cb980d78156cba45b4d31569303f5a576d
Author: Christian Kellner <gicmo gnome org>
Date:   Fri May 12 15:12:33 2017 +0200

    SystemInfo: strip sysfs strings better
    
    Use g_strstrip instead of just looking for trailing newlines.

 src/system-info.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/system-info.c b/src/system-info.c
index bd3bdd3..30604c4 100644
--- a/src/system-info.c
+++ b/src/system-info.c
@@ -435,8 +435,14 @@ read_sysfs_string(const char *node)
         return NULL;
     }
 
-    if (len > 1 && contents[len-1] == '\n') {
-        contents[len-1] = '\0';
+    if (contents == NULL) {
+        return NULL;
+    }
+
+    contents = g_strstrip(contents);
+
+    if (*contents == '\0') {
+        g_clear_pointer(&contents, g_free);
     }
 
     return contents;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]