Skip to content

Commit 7bd206a

Browse files
committed
Fix memory overflow
Duplicate of #190
1 parent 55ac9f0 commit 7bd206a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/cpuinfo_x86.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,9 @@ static void ParseLeaf2(const int max_cpuid_leaf, CacheInfo* info) {
11521152
// For newer AMD CPUs uses "CPUID, eax=0x8000001D"
11531153
static void ParseCacheInfo(const int max_cpuid_leaf, uint32_t leaf_id,
11541154
CacheInfo* info) {
1155-
for (int cache_id = 0; cache_id < CPU_FEATURES_MAX_CACHE_LEVEL; cache_id++) {
1155+
for (int cache_id = 0; cache_id < CPU_FEATURES_MAX_CACHE_LEVEL &&
1156+
info->size < CPU_FEATURES_MAX_CACHE_LEVEL;
1157+
cache_id++) {
11561158
const Leaf leaf = SafeCpuIdEx(max_cpuid_leaf, leaf_id, cache_id);
11571159
CacheType cache_type = ExtractBitRange(leaf.eax, 4, 0);
11581160
if (cache_type == CPU_FEATURE_CACHE_NULL) continue;

0 commit comments

Comments
 (0)