commit 24b08dce4b2dba6b9f9d3286751def9b497af6fc
parent a246f8329e0578ed046afa0b75e46a41395a0fa1
Author: sam-barr <samfbarr@outlook.com>
Date: Thu, 23 Apr 2020 21:07:35 -0500
fixed bug in get_cpu when model name doesn't contain @
Diffstat:
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/paleofetch.c b/paleofetch.c
@@ -16,6 +16,7 @@
#include "config.h"
#define BUF_SIZE 150
+#define REMOVE_CONST_STRING(A, B) remove_substring((A), (B), sizeof(B) - 1)
struct conf {
char *label, *(*function)();
@@ -324,7 +325,7 @@ char *get_cpu() {
/* read the model name into cpu_model, and increment num_cores every time model name is found */
while(getline(&line, &len, cpuinfo) != -1) {
- num_cores += sscanf(line, "model name : %[^@] @", cpu_model);
+ num_cores += sscanf(line, "model name : %[^\n@]", cpu_model);
}
free(line);
fclose(cpuinfo);
@@ -349,10 +350,14 @@ char *get_cpu() {
fclose(cpufreq);
/* remove unneeded information */
- remove_substring(cpu_model, "(R)", 3);
- remove_substring(cpu_model, "(TM)", 4);
- remove_substring(cpu_model, "Core", 4);
- remove_substring(cpu_model, "CPU", 3);
+ REMOVE_CONST_STRING(cpu_model, "(R)");
+ REMOVE_CONST_STRING(cpu_model, "(TM)");
+ REMOVE_CONST_STRING(cpu_model, "Dual-Core");
+ REMOVE_CONST_STRING(cpu_model, "Quad-Core");
+ REMOVE_CONST_STRING(cpu_model, "Six-Core");
+ REMOVE_CONST_STRING(cpu_model, "Eight-Core");
+ REMOVE_CONST_STRING(cpu_model, "Core");
+ REMOVE_CONST_STRING(cpu_model, "CPU");
char *cpu = malloc(BUF_SIZE);
snprintf(cpu, BUF_SIZE, "%s (%d) @ %.1fGHz", cpu_model, num_cores, freq);
@@ -395,7 +400,7 @@ char *find_gpu(int index) {
if (found == false) *gpu = '\0'; // empty string, so it will not be printed
pci_cleanup(pacc);
- remove_substring(gpu, "Corporation", 11);
+ REMOVE_CONST_STRING(gpu, "Corporation");
truncate_spaces(gpu);
return gpu;
}