Fix TableVal::DoClone to use CloneState cache

This commit is contained in:
Jon Siwek 2019-06-20 18:31:58 -07:00
parent 61d19d25e1
commit aefd9322fd
6 changed files with 38 additions and 13 deletions

View file

@ -1,4 +1,8 @@
2.6-479 | 2019-06-20 18:31:58 -0700
* Fix TableVal::DoClone to use CloneState cache (Jon Siwek, Corelight)
2.6-478 | 2019-06-20 14:19:11 -0700 2.6-478 | 2019-06-20 14:19:11 -0700
* Remove old Broccoli SSL options (Jon Siwek, Corelight) * Remove old Broccoli SSL options (Jon Siwek, Corelight)

View file

@ -1 +1 @@
2.6-478 2.6-479

View file

@ -2181,7 +2181,7 @@ Val* TableVal::DoClone(CloneState* state)
TableEntryVal* val; TableEntryVal* val;
while ( (val = tbl->NextEntry(key, cookie)) ) while ( (val = tbl->NextEntry(key, cookie)) )
{ {
TableEntryVal* nval = val->Clone(); TableEntryVal* nval = val->Clone(state);
tv->AsNonConstTable()->Insert(key, nval); tv->AsNonConstTable()->Insert(key, nval);
if ( subnets ) if ( subnets )

View file

@ -3,8 +3,6 @@
#ifndef val_h #ifndef val_h
#define val_h #define val_h
// BRO values.
#include <vector> #include <vector>
#include <list> #include <list>
#include <array> #include <array>
@ -374,6 +372,7 @@ protected:
friend class RecordVal; friend class RecordVal;
friend class VectorVal; friend class VectorVal;
friend class ValManager; friend class ValManager;
friend class TableEntryVal;
virtual void ValDescribe(ODesc* d) const; virtual void ValDescribe(ODesc* d) const;
virtual void ValDescribeReST(ODesc* d) const; virtual void ValDescribeReST(ODesc* d) const;
@ -804,9 +803,9 @@ public:
int(network_time - bro_start_network_time); int(network_time - bro_start_network_time);
} }
TableEntryVal* Clone() TableEntryVal* Clone(Val::CloneState* state)
{ {
auto rval = new TableEntryVal(val ? val->Clone() : nullptr); auto rval = new TableEntryVal(val ? val->Clone(state) : nullptr);
rval->last_access_time = last_access_time; rval->last_access_time = last_access_time;
rval->expire_access_time = expire_access_time; rval->expire_access_time = expire_access_time;
rval->last_read_update = last_read_update; rval->last_read_update = last_read_update;

View file

@ -1,2 +1,5 @@
direct assignment (PASS) direct assignment (PASS)
using copy (PASS) using copy (PASS)
F, T
F, T
[a=42], [a=42], [a=42], [a=42]

View file

@ -2,14 +2,12 @@
# @TEST-EXEC: btest-diff out # @TEST-EXEC: btest-diff out
function test_case(msg: string, expect: bool) function test_case(msg: string, expect: bool)
{ {
print fmt("%s (%s)", msg, expect ? "PASS" : "FAIL"); print fmt("%s (%s)", msg, expect ? "PASS" : "FAIL");
} }
event zeek_init() event zeek_init()
{ {
# "b" is not a copy of "a" # "b" is not a copy of "a"
local a: set[string] = set("this", "test"); local a: set[string] = set("this", "test");
local b: set[string] = a; local b: set[string] = a;
@ -25,6 +23,27 @@ event zeek_init()
delete c["this"]; delete c["this"];
test_case( "using copy", |d| == 2 && "this" in d); test_case( "using copy", |d| == 2 && "this" in d);
}
} type myrec: record {
a: count;
};
event zeek_init()
{
local v: vector of myrec;
local t: table[count] of myrec;
local mr = myrec($a = 42);
t[0] = mr;
t[1] = mr;
local tc = copy(t);
print same_object(t, tc), same_object(tc[0], tc[1]);
v[0] = mr;
v[1] = mr;
local vc = copy(v);
print same_object(v, vc), same_object(vc[0], vc[1]);
print tc[0], tc[1], vc[0], vc[1];
}