]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2438 in SNORT/snort3 from ~KATHARVE/snort3:cppcheck_fix to master
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Mon, 31 Aug 2020 12:20:25 +0000 (12:20 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Mon, 31 Aug 2020 12:20:25 +0000 (12:20 +0000)
Squashed commit of the following:

commit ff30d14526f064e5f5960b68e718585df543ed85
Author: Katura Harvey <katharve@cisco.com>
Date:   Sun Aug 30 14:18:30 2020 -0400

    http2_inspect: convert circular_array to std:vector

src/service_inspectors/http2_inspect/http2_hpack_dynamic_table.cc
src/service_inspectors/http2_inspect/http2_hpack_dynamic_table.h

index f90d77a41483724f6360514ccbc93c962762004d..ee1c349036f154578bb6892c59ea1d91e3d2fd49 100644 (file)
@@ -32,9 +32,11 @@ using namespace Http2Enums;
 
 HpackDynamicTable::~HpackDynamicTable()
 {
-    for (unsigned i = 0; i < ARRAY_CAPACITY; i++)
-        delete circular_array[i];
-    delete[] circular_array;
+    for (std::vector<HpackTableEntry*>::iterator it = circular_buf.begin();
+        it != circular_buf.end(); ++it)
+    {
+        delete *it;
+    }
 }
 
 bool HpackDynamicTable::add_entry(const Field& name, const Field& value)
@@ -55,14 +57,14 @@ bool HpackDynamicTable::add_entry(const Field& name, const Field& value)
 
     // Create new entry. This is done before pruning because the entry referenced by the new name
     // may be pruned.
-    HpackTableEntry *new_entry = new HpackTableEntry(name, value);
+    HpackTableEntrynew_entry = new HpackTableEntry(name, value);
 
     // If add entry would exceed max table size, evict old entries
     prune_to_size(max_size - new_entry_size);
 
     // Add new entry to the front of the table (newest entry = lowest index)
     start = (start + ARRAY_CAPACITY - 1) % ARRAY_CAPACITY;
-    circular_array[start] = new_entry;
+    circular_buf[start] = new_entry;
 
     num_entries++;
     if (num_entries > Http2Module::get_peg_counts(PEG_MAX_TABLE_ENTRIES))
@@ -80,7 +82,7 @@ const HpackTableEntry* HpackDynamicTable::get_entry(uint32_t virtual_index) cons
         return nullptr;
 
     const uint32_t arr_index = (start + dyn_index) % ARRAY_CAPACITY;
-    return circular_array[arr_index];
+    return circular_buf[arr_index];
 }
 
 /* This is called when adding a new entry and when receiving a dynamic table size update.
@@ -95,10 +97,10 @@ void HpackDynamicTable::prune_to_size(uint32_t new_max_size)
     {
         const uint32_t last_index = (start + num_entries - 1 + ARRAY_CAPACITY) % ARRAY_CAPACITY;
         num_entries--;
-        rfc_table_size -= circular_array[last_index]->name.length() +
-            circular_array[last_index]->value.length() + RFC_ENTRY_OVERHEAD;
-        delete circular_array[last_index];
-        circular_array[last_index] = nullptr;
+        rfc_table_size -= circular_buf[last_index]->name.length() +
+            circular_buf[last_index]->value.length() + RFC_ENTRY_OVERHEAD;
+        delete circular_buf[last_index];
+        circular_buf[last_index] = nullptr;
     }
 }
 
index 7a1f03bc4eff239e7c4e743be330177bef78af71..f062fb1a7400d2a2a19372cf2a87f5499344934a 100644 (file)
 
 #include "http2_enum.h"
 
+#include <vector>
+
 struct HpackTableEntry;
 
 class HpackDynamicTable
 {
 public:
     // FIXIT-P This array can be optimized to start smaller and grow on demand 
-    HpackDynamicTable() : circular_array(new HpackTableEntry*[ARRAY_CAPACITY]()) { }
+    HpackDynamicTable() : circular_buf(4096, nullptr) {}
     ~HpackDynamicTable();
     const HpackTableEntry* get_entry(uint32_t index) const;
     bool add_entry(const Field& name, const Field& value);
@@ -39,8 +41,6 @@ public:
     uint32_t get_max_size() { return max_size; }
 
 private:
-    void expand_array();
-
     const static uint32_t RFC_ENTRY_OVERHEAD = 32;
 
     const static uint32_t DEFAULT_MAX_SIZE = 4096;
@@ -50,7 +50,7 @@ private:
     uint32_t start = 0;
     uint32_t num_entries = 0;
     uint32_t rfc_table_size = 0;
-    HpackTableEntry** circular_array;
+    std::vector<HpackTableEntry*> circular_buf;
 
     void prune_to_size(uint32_t new_max_size);
 };