Really fix compilation; fix crash when pmodel is not present in cpuinfo

This commit is contained in:
Martin Kroeker 2022-07-31 00:41:04 +02:00 committed by GitHub
parent f727235be4
commit ef9c976a94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -88,18 +88,21 @@ int detect(void){
infile = fopen("/proc/cpuinfo", "r"); infile = fopen("/proc/cpuinfo", "r");
while (fgets(buffer, sizeof(buffer), infile)){ while (fgets(buffer, sizeof(buffer), infile)){
if(!strncmp(buffer, "model name", 10)){ if(!strncmp(buffer, "model name", 10)){
strcpy(model_buffer, buffer) strcpy(model_buffer, buffer);
pmodel = strchr(isa_buffer, ':') + 1; pmodel = strchr(isa_buffer, ':') + 1;
} }
if(!strncmp(buffer, "isa", 3)){ if(!strncmp(buffer, "isa", 3)){
strcpy(isa_buffer, buffer) strcpy(isa_buffer, buffer);
pisa = strchr(isa_buffer, '4') + 1; pisa = strchr(isa_buffer, '4') + 1;
} }
} }
fclose(infile); fclose(infile);
if (!pmodel)
return(CPU_GENERIC);
if (strstr(pmodel, check_c910_str) && strchr(pisa, 'v')) if (strstr(pmodel, check_c910_str) && strchr(pisa, 'v'))
return CPU_C910V; return CPU_C910V;