From 64db576b9e9d2dea8c83f271cb69669f7aaab18c Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Mon, 19 Jun 2017 15:47:36 +1000 Subject: [PATCH] fdr_confirm_compile: literals are now < 8 bytes --- src/fdr/fdr_confirm_compile.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/fdr/fdr_confirm_compile.cpp b/src/fdr/fdr_confirm_compile.cpp index b05d24a8..616ff86e 100644 --- a/src/fdr/fdr_confirm_compile.cpp +++ b/src/fdr/fdr_confirm_compile.cpp @@ -35,6 +35,7 @@ #include "util/alloc.h" #include "util/bitutils.h" #include "util/compare.h" +#include "util/container.h" #include "util/verify_types.h" #include @@ -47,19 +48,6 @@ namespace ue2 { using BC2CONF = map>; -// return the number of bytes beyond a length threshold in all strings in lits -static -size_t thresholdedSize(const vector &lits, size_t threshold) { - size_t tot = 0; - for (const auto &lit : lits) { - size_t sz = lit.s.size(); - if (sz > threshold) { - tot += ROUNDUP_N(sz - threshold, 8); - } - } - return tot; -} - static u64a make_u64a_mask(const vector &v) { assert(v.size() <= sizeof(u64a)); @@ -143,6 +131,11 @@ void fillLitInfo(const vector &lits, vector &tmpLitInfo, static bytecode_ptr getFDRConfirm(const vector &lits, bool make_small, bool make_confirm) { + // Every literal must fit within CONF_TYPE. + assert(all_of_in(lits, [](const hwlmLiteral &lit) { + return lit.s.size() <= sizeof(CONF_TYPE); + })); + vector tmpLitInfo(lits.size()); CONF_TYPE andmsk; fillLitInfo(lits, tmpLitInfo, andmsk); @@ -271,12 +264,11 @@ bytecode_ptr getFDRConfirm(const vector &lits, #endif const size_t bitsToLitIndexSize = (1U << nBits) * sizeof(u32); - const size_t totalLitSize = thresholdedSize(lits, sizeof(CONF_TYPE)); // this size can now be a worst-case as we can always be a bit smaller size_t size = ROUNDUP_N(sizeof(FDRConfirm), alignof(u32)) + ROUNDUP_N(bitsToLitIndexSize, alignof(LitInfo)) + - sizeof(LitInfo) * lits.size() + totalLitSize; + sizeof(LitInfo) * lits.size(); size = ROUNDUP_N(size, alignof(FDRConfirm)); auto fdrc = make_zeroed_bytecode_ptr(size);