From f6f760b5f869bf7d0e60d3ff113663a9b14708cd Mon Sep 17 00:00:00 2001 From: "dsites@google.com" Date: Mon, 15 Jul 2013 23:22:13 +0000 Subject: [PATCH] Add missing check for too many language hints git-svn-id: https://cld2.googlecode.com/svn/trunk@11 b252ecd4-b096-bf77-eb8e-91563289f87e --- internal/compact_lang_det_hint_code.cc | 6 ++++-- internal/compact_lang_det_hint_code.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) 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