[common] cpuinfo: trim any trailing whitespace from CPU model

This commit is contained in:
Geoffrey McRae 2021-08-31 20:20:11 +10:00
parent 977a4f6323
commit 5fc561fa63

View File

@ -25,6 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
bool lgCPUInfo(char * model, size_t modelSize, int * procs, int * cores) 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, ": "); const char * name = strstr(buffer, ": ");
if (name) if (name)
name += 2; 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; model = NULL;
} }
else if (cores && strncmp(buffer, "cpu cores", 9) == 0) else if (cores && strncmp(buffer, "cpu cores", 9) == 0)