From: Steinar H. Gunderson Date: Tue, 20 Oct 2020 16:55:37 +0000 (+0200) Subject: Fix a crash when we have a too few blocks to train a dictionary. X-Git-Tag: 1.0.6~2 X-Git-Url: https://git.sesse.net/?p=plocate;a=commitdiff_plain;h=93d57f8f19e57efbb91e139bfca1064bd9e27bb3 Fix a crash when we have a too few blocks to train a dictionary. --- diff --git a/plocate-build.cpp b/plocate-build.cpp index 6d393e4..c42bd86 100644 --- a/plocate-build.cpp +++ b/plocate-build.cpp @@ -222,6 +222,9 @@ string DictionaryBuilder::train(size_t buf_size) string buf; buf.resize(buf_size); size_t ret = ZDICT_trainFromBuffer(&buf[0], buf_size, dictionary_buf.data(), lengths.data(), lengths.size()); + if (ret == size_t(-1)) { + return ""; + } dprintf("Sampled %zu bytes in %zu blocks, built a dictionary of size %zu\n", dictionary_buf.size(), lengths.size(), ret); buf.resize(ret);