]> git.sesse.net Git - plocate/commitdiff
Fix a crash when we have a too few blocks to train a dictionary.
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Tue, 20 Oct 2020 16:55:37 +0000 (18:55 +0200)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Tue, 20 Oct 2020 16:55:37 +0000 (18:55 +0200)
plocate-build.cpp

index 6d393e444c830bb396db9f873c5f1015e3352af2..c42bd86113cd2eae8ba53cba7ca9625e573d9465 100644 (file)
@@ -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);