diff --git a/internal/compact_lang_det_hint_code.cc b/internal/compact_lang_det_hint_code.cc index eafb899..fc1f0ae 100644 --- a/internal/compact_lang_det_hint_code.cc +++ b/internal/compact_lang_det_hint_code.cc @@ -949,7 +949,8 @@ void MergeCLDLangPriorsMax(OneCLDLangPrior olp, CLDLangPriors* lps) { return; } } - // Not found; add it + // Not found; add it if room + if (lps->n >= kMaxOneCLDLangPrior) {return;} lps->prior[lps->n++] = olp; } @@ -964,7 +965,8 @@ void MergeCLDLangPriorsBoost(OneCLDLangPrior olp, CLDLangPriors* lps) { return; } } - // Not found; add it + // Not found; add it if room + if (lps->n >= kMaxOneCLDLangPrior) {return;} lps->prior[lps->n++] = olp; } diff --git a/internal/compact_lang_det_hint_code.h b/internal/compact_lang_det_hint_code.h index 1dc8b4f..df8948a 100644 --- a/internal/compact_lang_det_hint_code.h +++ b/internal/compact_lang_det_hint_code.h @@ -31,9 +31,10 @@ namespace CLD2 { // Full language in bottom 10 bits, weight in top 6 bits typedef int16 OneCLDLangPrior; +const int kMaxOneCLDLangPrior = 14; typedef struct { int32 n; - OneCLDLangPrior prior[14]; + OneCLDLangPrior prior[kMaxOneCLDLangPrior]; } CLDLangPriors; // Reading exposed here; setting hidden in .cc