mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.96] Fix segfault when invalid cache size is found
This commit is contained in:
@@ -314,6 +314,9 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
cpu->cach = get_cache_info(cpu);
|
cpu->cach = get_cache_info(cpu);
|
||||||
cpu->topo = get_topology_info(cpu, cpu->cach);
|
cpu->topo = get_topology_info(cpu, cpu->cach);
|
||||||
|
|
||||||
|
if(cpu->cach == NULL || cpu->topo == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return cpu;
|
return cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,29 +630,23 @@ struct cache* get_cache_info(struct cpuInfo* cpu) {
|
|||||||
// The values were chosen by me
|
// The values were chosen by me
|
||||||
if(cach->L1i->size > 64 * 1024) {
|
if(cach->L1i->size > 64 * 1024) {
|
||||||
printBug("Invalid L1i size: %dKB", cach->L1i->size/1024);
|
printBug("Invalid L1i size: %dKB", cach->L1i->size/1024);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
if(cach->L1d->size > 64 * 1024) {
|
if(cach->L1d->size > 64 * 1024) {
|
||||||
printBug("Invalid L1d size: %dKB", cach->L1d->size/1024);
|
printBug("Invalid L1d size: %dKB", cach->L1d->size/1024);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
if(cach->L2->exists) {
|
if(cach->L2->exists) {
|
||||||
if(cach->L3->exists && cach->L2->size > 2 * 1048576) {
|
if(cach->L3->exists && cach->L2->size > 2 * 1048576) {
|
||||||
printBug("Invalid L2 size: %dMB", cach->L2->size/(1048576));
|
printBug("Invalid L2 size: %dMB", cach->L2->size/(1048576));
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
else if(cach->L2->size > 100 * 1048576) {
|
else if(cach->L2->size > 100 * 1048576) {
|
||||||
printBug("Invalid L2 size: %dMB", cach->L2->size/(1048576));
|
printBug("Invalid L2 size: %dMB", cach->L2->size/(1048576));
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(cach->L3->exists && cach->L3->size > 100 * 1048576) {
|
if(cach->L3->exists && cach->L3->size > 100 * 1048576) {
|
||||||
printBug("Invalid L3 size: %dMB", cach->L3->size/(1048576));
|
printBug("Invalid L3 size: %dMB", cach->L3->size/(1048576));
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
if(!cach->L2->exists) {
|
if(!cach->L2->exists) {
|
||||||
printBug("Could not find L2 cache");
|
printBug("Could not find L2 cache");
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cach;
|
return cach;
|
||||||
|
|||||||
Reference in New Issue
Block a user