]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
fdr: reduce confirm size to a u8
authorJustin Viiret <justin.viiret@intel.com>
Tue, 13 Sep 2016 05:52:39 +0000 (15:52 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Fri, 28 Oct 2016 03:52:52 +0000 (14:52 +1100)
Also removes the flexible array member from the LitInfo structure.

src/fdr/fdr_confirm.h
src/fdr/fdr_confirm_compile.cpp
src/fdr/fdr_confirm_runtime.h

index 865218b471b376bdd619276cac91a4b60412c8b3..6ce85afd033d0ce89c7d67d7ebf51b4bba3e03a5 100644 (file)
@@ -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
index f84ed40249f410295b55fdc6a96ae06ea22a0129..e77c46d1fe919593939fac7cdf548a3381531ae6 100644 (file)
@@ -107,7 +107,7 @@ void fillLitInfo(const vector<hwlmLiteral> &lits, vector<LitInfo> &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<hwlmLiteral> &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));
index 2b0cd59557c2b666912af5d98d192ba7bd08c172..87ade9feaa3703f4d60404c3f37d1c5863a73571 100644 (file)
@@ -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;
                 }