From 2f47cce8a616397305dbeed8c631ab08ab2d528b Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sat, 27 Feb 2021 08:34:38 -0800 Subject: [PATCH] fixes for now-incorrect assumption that GetField always returns an existing ValPtr --- src/CompHash.cc | 7 ++++--- src/file_analysis/File.cc | 8 ++++---- src/option.bif | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index 2f19771637..506c4626af 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -184,7 +184,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, for ( int i = 0; i < num_fields; ++i ) { - auto rv_i = rv->GetField(i).get(); + auto rv_i = rv->GetField(i); Attributes* a = rt->FieldDecl(i)->attrs.get(); bool optional = (a && a->Find(ATTR_OPTIONAL)); @@ -194,7 +194,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, if ( ! (kp = SingleValHash(type_check, kp, rt->GetFieldType(i).get(), - rv_i, optional)) ) + rv_i.get(), optional)) ) return nullptr; } @@ -517,8 +517,9 @@ int CompositeHash::SingleTypeKeySize(Type* bt, const Val* v, Attributes* a = rt->FieldDecl(i)->attrs.get(); bool optional = (a && a->Find(ATTR_OPTIONAL)); + auto rv_v = rv ? rv->GetField(i) : nullptr; sz = SingleTypeKeySize(rt->GetFieldType(i).get(), - rv ? rv->GetField(i).get() : nullptr, + rv_v.get(), type_check, sz, optional, calc_static_size); if ( ! sz ) diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 16b5ac1e9f..a879a16aa4 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -128,12 +128,12 @@ bool File::UpdateConnectionFields(Connection* conn, bool is_orig) if ( ! conn ) return false; - Val* conns = val->GetField(conns_idx).get(); + auto conns = val->GetField(conns_idx); if ( ! conns ) { auto ect = empty_connection_table(); - conns = ect.get(); + conns = ect; val->Assign(conns_idx, std::move(ect)); } @@ -309,7 +309,7 @@ void File::InferMetadata() { did_metadata_inference = true; - Val* bof_buffer_val = val->GetField(bof_buffer_idx).get(); + auto bof_buffer_val = val->GetField(bof_buffer_idx); if ( ! bof_buffer_val ) { @@ -318,7 +318,7 @@ void File::InferMetadata() String* bs = concatenate(bof_buffer.chunks); val->Assign(bof_buffer_idx, bs); - bof_buffer_val = val->GetField(bof_buffer_idx).get(); + bof_buffer_val = val->GetField(bof_buffer_idx); } if ( ! FileEventAvailable(file_sniff) ) diff --git a/src/option.bif b/src/option.bif index 496baae0cc..fca30b3bdf 100644 --- a/src/option.bif +++ b/src/option.bif @@ -80,7 +80,8 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool if ( same_type(val->GetType(), zeek::Broker::detail::DataVal::ScriptDataType()) ) { - auto dv = static_cast(val->AsRecordVal()->GetField(0).get()); + auto valptr = val->AsRecordVal()->GetField(0); + auto dv = static_cast(valptr.get()); auto val_from_data = dv->castTo(i->GetType().get()); if ( ! val_from_data )