From f7cc8a618d7c5b0d331dbca6ff95062e50436a88 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Tue, 13 Sep 2016 15:52:39 +1000 Subject: [PATCH] fdr: reduce confirm size to a u8 Also removes the flexible array member from the LitInfo structure. --- src/fdr/fdr_confirm.h | 9 ++++----- src/fdr/fdr_confirm_compile.cpp | 6 +++--- src/fdr/fdr_confirm_runtime.h | 5 +++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/fdr/fdr_confirm.h b/src/fdr/fdr_confirm.h index 865218b4..6ce85afd 100644 --- a/src/fdr/fdr_confirm.h +++ b/src/fdr/fdr_confirm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Intel Corporation + * Copyright (c) 2015-2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -52,19 +52,18 @@ typedef enum LitInfoFlags { /** * \brief Structure describing a literal, linked to by FDRConfirm. * - * This structure is followed in memory by a variable-sized string prefix at - * LitInfo::s, for strings that are longer than CONF_TYPE. + * This structure is followed in memory by a variable-sized string prefix, for + * strings that are longer than CONF_TYPE. */ struct LitInfo { CONF_TYPE v; CONF_TYPE msk; hwlm_group_t groups; - u32 size; u32 id; // literal ID as passed in + u8 size; u8 flags; /* LitInfoFlags */ u8 next; u8 extended_size; - u8 s[1]; // literal prefix, which continues "beyond" this struct. }; #define FDRC_FLAG_NO_CONFIRM 1 diff --git a/src/fdr/fdr_confirm_compile.cpp b/src/fdr/fdr_confirm_compile.cpp index f84ed402..e77c46d1 100644 --- a/src/fdr/fdr_confirm_compile.cpp +++ b/src/fdr/fdr_confirm_compile.cpp @@ -107,7 +107,7 @@ void fillLitInfo(const vector &lits, vector &tmpLitInfo, info.extended_size = verify_u8(lit.msk.size()); } info.flags = flags; - info.size = verify_u32(lit.s.size()); + info.size = verify_u8(lit.s.size()); info.groups = lit.groups; // these are built up assuming a LE machine @@ -333,8 +333,8 @@ getFDRConfirm(const vector &lits, bool applyOneCharOpt, const string &t = lits[litIdx].s; if (t.size() > sizeof(CONF_TYPE)) { size_t prefix_len = t.size() - sizeof(CONF_TYPE); - memcpy(&finalLI.s[0], t.c_str(), prefix_len); - ptr = &finalLI.s[0] + prefix_len; + memcpy(ptr, t.c_str(), prefix_len); + ptr += prefix_len; } ptr = ROUNDUP_PTR(ptr, alignof(LitInfo)); diff --git a/src/fdr/fdr_confirm_runtime.h b/src/fdr/fdr_confirm_runtime.h index 2b0cd595..87ade9fe 100644 --- a/src/fdr/fdr_confirm_runtime.h +++ b/src/fdr/fdr_confirm_runtime.h @@ -86,7 +86,7 @@ void confWithBit(const struct FDRConfirm *fdrc, const struct FDR_Runtime_Args *a // as for the regular case, no need to do a full confirm if // we're a short literal if (unlikely(li->size > sizeof(CONF_TYPE))) { - const u8 *s1 = li->s; + const u8 *s1 = (const u8 *)li + sizeof(*li); const u8 *s2 = s1 + full_overhang; const u8 *loc1 = history + len_history - full_overhang; const u8 *loc2 = buf; @@ -106,7 +106,8 @@ void confWithBit(const struct FDRConfirm *fdrc, const struct FDR_Runtime_Args *a // if string < conf_type we don't need regular string cmp if (unlikely(li->size > sizeof(CONF_TYPE))) { - if (cmpForward(loc, li->s, li->size - sizeof(CONF_TYPE), + const u8 *s = (const u8 *)li + sizeof(*li); + if (cmpForward(loc, s, li->size - sizeof(CONF_TYPE), caseless)) { goto out; }