From 6efb6c0ffe7b7345b4b2349b1bd1b8f33dc6c7fd Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Wed, 15 Aug 2012 11:08:08 -0400 Subject: Throw exception for binary files with too large order / Ondrej Bojar --- lm/model.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lm') diff --git a/lm/model.cc b/lm/model.cc index 6547ba03d..aace40df9 100644 --- a/lm/model.cc +++ b/lm/model.cc @@ -48,6 +48,7 @@ template GenericModel::Ge } template void GenericModel::InitializeFromBinary(void *start, const Parameters ¶ms, const Config &config, int fd) { + UTIL_THROW_IF(params.counts.size() > KENLM_MAX_ORDER, FormatLoadException, "This model has order " << params.counts.size() << ". Re-compile (use -a), passing a number at least this large to bjam's --max-kenlm-order flag."); SetupMemory(start, params.counts, config); vocab_.LoadedBinary(params.fixed.has_vocabulary, fd, config.enumerate_vocab); search_.LoadedBinary(); @@ -61,7 +62,7 @@ template void GenericModel KENLM_MAX_ORDER) UTIL_THROW(FormatLoadException, "This model has order " << counts.size() << ". Re-compile, passing a number at least this large to bjam's --max-kenlm-order flag."); + UTIL_THROW_IF(counts.size() > KENLM_MAX_ORDER, FormatLoadException, "This model has order " << counts.size() << ". Re-compile (use -a), passing a number at least this large to bjam's --max-kenlm-order flag."); if (counts.size() < 2) UTIL_THROW(FormatLoadException, "This ngram implementation assumes at least a bigram model."); if (config.probing_multiplier <= 1.0) UTIL_THROW(ConfigException, "probing multiplier must be > 1.0"); -- cgit v1.2.3