From 93d57f8f19e57efbb91e139bfca1064bd9e27bb3 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 20 Oct 2020 18:55:37 +0200 Subject: [PATCH] Fix a crash when we have a too few blocks to train a dictionary. --- plocate-build.cpp | 3 +++ 1 file changed, 3 insertions(+) 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); -- 2.39.2