From c7d0b67a8042f17a75fbf24629368c87151a00fb Mon Sep 17 00:00:00 2001 From: Herman Semenov Date: Fri, 16 Feb 2024 15:04:25 +0300 Subject: [PATCH] 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 --- common/common.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/common.cpp b/common/common.cpp index f64da2cb6..a384c82b4 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -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 (seqs.find(cs_curr[j]) == seqs.end()) { 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; }