From ef9c976a94d30c374061400faf9cf3d75b30c476 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sun, 31 Jul 2022 00:41:04 +0200 Subject: [PATCH] Really fix compilation; fix crash when pmodel is not present in cpuinfo --- cpuid_riscv64.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cpuid_riscv64.c b/cpuid_riscv64.c index e4687945f..894d2b873 100644 --- a/cpuid_riscv64.c +++ b/cpuid_riscv64.c @@ -88,18 +88,21 @@ int detect(void){ infile = fopen("/proc/cpuinfo", "r"); while (fgets(buffer, sizeof(buffer), infile)){ if(!strncmp(buffer, "model name", 10)){ - strcpy(model_buffer, buffer) + strcpy(model_buffer, buffer); pmodel = strchr(isa_buffer, ':') + 1; } if(!strncmp(buffer, "isa", 3)){ - strcpy(isa_buffer, buffer) + strcpy(isa_buffer, buffer); pisa = strchr(isa_buffer, '4') + 1; } } fclose(infile); + if (!pmodel) + return(CPU_GENERIC); + if (strstr(pmodel, check_c910_str) && strchr(pisa, 'v')) return CPU_C910V;