From 5fc561fa631279e72a7540f78144d2aa32b737fa Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 31 Aug 2021 20:20:11 +1000 Subject: [PATCH] [common] cpuinfo: trim any trailing whitespace from CPU model --- common/src/platform/linux/cpuinfo.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/src/platform/linux/cpuinfo.c b/common/src/platform/linux/cpuinfo.c index e3dc5cbe..e9d501c3 100644 --- a/common/src/platform/linux/cpuinfo.c +++ b/common/src/platform/linux/cpuinfo.c @@ -25,6 +25,7 @@ #include #include #include +#include bool lgCPUInfo(char * model, size_t modelSize, int * procs, int * cores) { @@ -51,7 +52,13 @@ bool lgCPUInfo(char * model, size_t modelSize, int * procs, int * cores) const char * name = strstr(buffer, ": "); if (name) name += 2; - snprintf(model, modelSize, "%s", name ? name : "Unknown"); + int len = snprintf(model, modelSize, "%s", name ? name : "Unknown"); + + // trim any whitespace + while(len > 0 && isspace(model[len-1])) + --len; + model[len] = '\0'; + model = NULL; } else if (cores && strncmp(buffer, "cpu cores", 9) == 0)