1
0
mirror of https://github.com/google/cpu_features.git synced 2025-04-27 23:22:31 +02:00

Fix memory overflow

Duplicate of #190
This commit is contained in:
Guillaume Chatelet 2021-10-26 13:58:42 +00:00
parent 55ac9f0556
commit 7bd206a75f

View File

@ -1152,7 +1152,9 @@ static void ParseLeaf2(const int max_cpuid_leaf, CacheInfo* info) {
// For newer AMD CPUs uses "CPUID, eax=0x8000001D"
static void ParseCacheInfo(const int max_cpuid_leaf, uint32_t leaf_id,
CacheInfo* info) {
for (int cache_id = 0; cache_id < CPU_FEATURES_MAX_CACHE_LEVEL; cache_id++) {
for (int cache_id = 0; cache_id < CPU_FEATURES_MAX_CACHE_LEVEL &&
info->size < CPU_FEATURES_MAX_CACHE_LEVEL;
cache_id++) {
const Leaf leaf = SafeCpuIdEx(max_cpuid_leaf, leaf_id, cache_id);
CacheType cache_type = ExtractBitRange(leaf.eax, 4, 0);
if (cache_type == CPU_FEATURE_CACHE_NULL) continue;