diff --git a/src/ppc/ppc.c b/src/ppc/ppc.c index 50b0897..70a9df5 100644 --- a/src/ppc/ppc.c +++ b/src/ppc/ppc.c @@ -44,6 +44,17 @@ struct cache* get_cache_info(struct cpuInfo* cpu) { return cach; } +bool check_package_ids_integrity(int* package_ids, int total_cores) { + for(int i=0; i < total_cores; i++) { + if(package_ids[i] >= total_cores || package_ids[i] < 0) { + printBug("check_package_ids_integrity: package_ids[%d]=%d", i, package_ids[i]); + return false; + } + } + + return true; +} + struct topology* get_topology_info(struct cache* cach) { struct topology* topo = emalloc(sizeof(struct topology)); init_topology_struct(topo, cach); @@ -68,6 +79,10 @@ struct topology* get_topology_info(struct cache* cach) { for(int i=0; i < topo->total_cores; i++) package_ids[i] = 0; } + if(!check_package_ids_integrity(package_ids, topo->total_cores)) { + return NULL; + } + // 2. Socket detection int *package_ids_count = emalloc(sizeof(int) * topo->total_cores); for(int i=0; i < topo->total_cores; i++) {