common : fixed critical UB inserting map size into himself

More info: https://stackoverflow.com/questions/61546383/is-inserting-map-size-as-value-into-a-map-undefined-behavior
This commit is contained in:
Herman Semenov 2024-02-16 15:04:25 +03:00
parent 0d4177126b
commit c7d0b67a80

View file

@ -1774,7 +1774,9 @@ void dump_kv_cache_view_seqs(const llama_kv_cache_view & view, int row_size) {
if (cs_curr[j] < 0) { continue; } if (cs_curr[j] < 0) { continue; }
if (seqs.find(cs_curr[j]) == seqs.end()) { if (seqs.find(cs_curr[j]) == seqs.end()) {
if (seqs.size() + 1 >= sizeof(slot_chars)) { break; } if (seqs.size() + 1 >= sizeof(slot_chars)) { break; }
seqs[cs_curr[j]] = seqs.size(); seqs[cs_curr[j]] = 0;
const auto size = seqs.size();
seqs[cs_curr[j]] = size;
} }
} }
if (seqs.size() + 1 >= sizeof(slot_chars)) { break; } if (seqs.size() + 1 >= sizeof(slot_chars)) { break; }