mbpfan-josie

Initialize fan label when it cannot be read

read_value_str left the buffer untouched when the label file was
missing or fgets failed, so the malloc'ed fan->label was passed to
strlen and printed while uninitialized.  Always leave an empty string
in that case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

7eeb9dcf635236d6cca823bf522661e9eea9fbdb
Andrew Gaul <andrew@gaul.org> · 2026-11-08T11:29 · browse files at this commit

parents: 5ad2140

diff --git a/src/mbpfan.c b/src/mbpfan.c
index 7f36389..645b009 100644
--- a/src/mbpfan.c
+++ b/src/mbpfan.c
@@ -255,9 +255,12 @@ static int read_value(const char *path)
 
 static void read_value_str(const char *path, char *str, size_t len)
 {
+    str[0] = '\0';
     FILE *file = fopen(path, "r");
     if (file != NULL) {
-        fgets(str, len, file);
+        if (fgets(str, len, file) == NULL) {
+            str[0] = '\0';
+        }
         fclose(file);
     }
 }