mbpfan-josie

Only trim trailing whitespace from fan labels

trim_trailing_whitespace replaced every whitespace character in the
string, not just the trailing ones, so a label like "Left side" was
truncated to "Left".  Stop at the first non-whitespace character.  Also
cast to unsigned char before calling isspace and drop the redundant
'\n' check.

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

5ad2140997a509066a611e716c851f46a36897b4
Andrew Gaul <andrew@gaul.org> · 2026-11-08T11:26 · browse files at this commit

parents: bf6650e

diff --git a/src/mbpfan.c b/src/mbpfan.c
index 8d1226a..7f36389 100644
--- a/src/mbpfan.c
+++ b/src/mbpfan.c
@@ -265,9 +265,10 @@ static void read_value_str(const char *path, char *str, size_t len)
 static void trim_trailing_whitespace(char *str)
 {
     for (ssize_t i = strlen(str) - 1; i >= 0; --i) {
-        if (isspace(str[i]) || str[i] == '\n') {
-            str[i] = '\0';
+        if (!isspace((unsigned char)str[i])) {
+            break;
         }
+        str[i] = '\0';
     }
 }