Commit graph

68 commits

Author SHA1 Message Date
Tim Wojtulewicz
ee319fc1c5 Fix clang-tidy modernize-use-nullptr findings 2025-06-06 11:43:06 -07:00
Arne Welzel
0f1c1cb754 clang-format: Sort doctest header at the bottom 2024-11-15 17:00:00 +01:00
Benjamin Bannier
f5a76c1aed Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The
one place where we deviate is header include order since Zeek depends on
headers being included in a certain order.
2023-10-30 09:40:55 +01:00
Tim Wojtulewicz
90d0bc64fa Replace empty destructor bodies with =default definitions 2023-07-07 09:17:05 -07:00
Tim Wojtulewicz
57ae03dd7d Add support for itertors with ordered dictionaries 2022-10-10 10:08:58 -07:00
Tim Wojtulewicz
02cc4fd1b8 Remove unused headers from Dict.cc 2022-09-20 13:04:04 -07:00
Tim Wojtulewicz
47e7fe2cd1 Convert Dictionary types to be templated classes
This has the fortunate side-effect of also making it so we can store
the value objects as typed pointers, instead of void*.
2022-07-05 13:33:34 -07:00
Tim Wojtulewicz
035c543e9f Remove loops from Dict iterator invalidation unit test
This fixes Coverity finding 1490366
2022-07-01 14:35:54 -07:00
Tim Wojtulewicz
392c2f3810 Remove deprecated IterCookie-based dictionary iteration 2022-06-30 19:06:01 +00:00
Tim Wojtulewicz
70e63d4749 Remove deprecated MemoryAllocation() methods and related code 2022-06-30 18:56:52 +00:00
Tim Wojtulewicz
7c4fd382d9 Code modernization: Convert from deprecated C standard library headers 2022-06-27 09:47:31 -07:00
Tim Wojtulewicz
3397beabf7 Use ZEEK_DICT_DEBUG more in Dict.cc instead of DEBUG 2022-05-23 14:12:39 -07:00
Robin Sommer
09b132728c
Fix another crash during dictionary iteration.
Closes #2017.
2022-04-14 11:11:57 +02:00
Robin Sommer
6491db6617
Fix assertions in dictionary that can trigger for benign reasons.
These assertions were checking for a situation that I believe can
happen legitimately: a robust iterator pointing to an index that,
after some table resizing, happens to be inside the overflow area and
hence empty. We'll now move it to the end of the table in the case.
2022-04-14 11:11:03 +02:00
Robin Sommer
b4f52ff311
Fix robust iterators when modifying dictionary during iteration.
When inserting/deleting elements, we now remove their `DictEntries`
from any robust iterators' bookkeeping. First, we don't need that
information anymore, and second the `DictEntries` contain pointers
that may become invalid.

I don't know how to write a unit test for this unfortunately because
it depends on where exactly things land in the hash table.

Btw, memory mgmt for DictEntries is pretty fragile: They contain
pointers to both memory they own (`key`) and memory they don't own
(`value`). The former type of pointers is shallow-copied on
assignment/copy-construction, meaning that there can be multiple
instances seemingly owning the same memory. That only works because
deletion is manual, and not part of standard destruction. The second
type of pointer has a similar problem, except that it's managed
externally. It's important to not end up with multiple `DictEntries`
pointing to the same value (which is actually what that iterator
bookkeeping did).

Addresses #2032.
2022-04-14 11:11:03 +02:00
Tim Wojtulewicz
9af6b2f48d clang-format: Set penalty for breaking after assignment operator 2021-09-27 10:49:48 -07:00
Tim Wojtulewicz
07e276ab2e clang-format: A few minor comment-spacing fixes 2021-09-25 11:52:55 -07:00
Tim Wojtulewicz
b2f171ec69 Reformat the world 2021-09-16 15:35:39 -07:00
Vern Paxson
9f68002392 factoring to support debugging of Dict iterators - no semantic changes 2021-09-08 10:23:38 -07:00
Tim Wojtulewicz
41273afad8 GH-1693: Fix potential crash with elements being modified during robust iteration 2021-07-26 11:22:38 -07:00
Tim Wojtulewicz
9b15db25f6 Reorder fields in some classes for more compact memory layout 2021-07-14 14:59:49 -07:00
Tim Wojtulewicz
a7fd34375f GH-572: Mark MemoryAllocation() and related methods deprecated 2021-06-28 11:07:58 -07:00
Tim Wojtulewicz
6ab317f7bd GH-1546: Make DictIterator() public, add copy/move operators 2021-05-17 11:57:17 -07:00
Jon Siwek
292e3e18a3 Add a fatal error condition for invalid Dictionary insertion distances
When choosing poor/aggressive values for `table_expire_interval`,
`table_expire_delay`, and/or `table_incremental_step` that tend to
leave tables in state of constant table-expiry-iteration, the underlying
Dictionary is never allowed the chance to complete remapping operations
which re-position entries to more ideal locations (e.g. after
reallocating the table to be able to store more entries).

That situation not only leads to the Dictionary generally having a less
efficient structure, but eventually, the lack of re-positioning may
cause an insertion to calculate the new entry's
distance-from-ideal-position to be a value requiring a full 16-bits or
more (>=65535), but an entry only allows storing 16-bit distance values,
with 65535 being a sentinel value that is supposed to indicate an empty
entry.  Dictionary operations may start misbehaving if that's allowed to
happen.
2021-04-26 23:03:32 -07:00
Jon Siwek
8a8a983c49 Add missing zeek/ to header includes
Related to https://github.com/zeek/zeek/pull/1377
2021-01-29 19:16:29 -08:00
Tim Wojtulewicz
892124378c Implement standard-library-compatible iterators for Dictionary 2021-01-14 13:49:40 -07:00
Jon Siwek
8f98b068c8 GH-1328: Improve behavior of Dictionary iterator invalidation
Previously, an assertion was triggered in debug builds upon any attempt
to insert or remove a Dictionary entry while any iteration of that
Dictionary is underway and also even in cases where Dictionary membership
was not actually modified (and thus invalidates a loop).

Now, it emits run-time warnings regardless of build-type and only when
insert/remove operations truly change the Dictionary membership.  In the
context of a Zeek script causing an invalidation, the warning message
also now helps pinpoint the exact expression that causes it.
2020-12-11 18:52:31 -08:00
Tim Wojtulewicz
96d9115360 GH-1079: Use full paths starting with zeek/ when including files 2020-11-12 12:15:26 -07:00
Jon Siwek
3c4de51f40 GH-1208: Use Dictionary validity assertions only during CI 2020-10-13 14:59:11 -07:00
Tim Wojtulewicz
fe0c22c789 Base: Clean up explicit uses of namespaces in places where they're not necessary.
This commit covers all of the common and base classes.
2020-08-24 12:07:00 -07:00
Tim Wojtulewicz
046eb58b75 Merge remote-tracking branch 'origin/topic/timw/266-namespaces-part4'
* origin/topic/timw/266-namespaces-part4: (34 commits)
  Add missing namespace to usage of get_exe_path in fuzzer
  Rename methods in RunState to remove 'net' from their names
  Move zeek::net namespace to zeek::run_state namespace.
  Move ScannedFile class and associated globals into ScannedFile.h and out of Net.h and scan.l
  Rename types in ZeekList.h to be consistent with the style guide
  Move NetVar from zeek to zeek::detail namespace
  Remove PRI_PTR_COMPAT macros
  Fix indentation of namespaced aliases
  Move zeek-setup code into namespaces
  Move ZeekList types to zeek namespace
  Move __RegisterBif from zeek::detail::plugin to zeek::plugin::detail
  Remove unimplemented zeek_magic_path/bro_magic_path method
  Move all plugin classes into zeek::plugin::detail namespaces
  Rename BroList.h to ZeekList.h
  Move a few smaller files to zeek namespaces
  Tag the end of some namespaces for consistency
  Move a few of the zeek::util methods and variables to zeek::util::detail
  Move zeekygen code to zeek::zeekygen::detail namespace
  Mark zeek::util::pad_size as constexpr, which provides a small performance improvement
  Move everything in util.h to zeek::util namespace.
  ...
2020-08-21 08:37:38 -07:00
Tim Wojtulewicz
ddf48d7529 Move a few of the zeek::util methods and variables to zeek::util::detail 2020-08-20 16:11:44 -07:00
Tim Wojtulewicz
ce98666621 Fix a number of Coverity issues in Dict
1431186: Asserting that an unsigned value is >= 0 is pointless
1431188/1431189/1431191: Side effect of using an assignment operator in a call to ASSERT()
1431193: Dereference after null check could lead to null being used
1431195: Use of rand() replaced with random()
2020-08-17 11:31:22 -07:00
Tim Wojtulewicz
f1ed66d52c Fix some printf warnings with size_t values 2020-08-11 13:42:03 -07:00
Tim Wojtulewicz
47f3eb69fa Move Dict constants to detail namespace 2020-08-11 11:26:22 -07:00
Jon Siwek
ba1611c21f Adjust Dict whitespace/style 2020-08-11 11:26:22 -07:00
Jon Siwek
37d3cfbd44 Fix new/malloc/delete/free mismatches in Dictionary code 2020-08-11 11:26:21 -07:00
Jon Siwek
d566b8ca31 Add explanation for a Dict TODO item 2020-08-11 11:26:21 -07:00
Jon Siwek
1d33dbc6bc Fix compiler warning in Dictionary debug/dump printf format string 2020-08-11 11:26:21 -07:00
Tim Wojtulewicz
0c7e4d62ee Overwrite old Dict.h/cc with new ones 2020-08-11 11:26:21 -07:00
jasonlue
d3eeeb0f4c add Clustered Hashing based Open Addressing Dict. To replace the existing dict, #define USE_OPEN_DICT 2020-08-11 11:26:21 -07:00
Tim Wojtulewicz
a243c0e4a6 Overwrite old Dict.h/cc with new ones 2020-08-09 21:27:23 -07:00
jasonlue
19f063f2a3 add Clustered Hashing based Open Addressing Dict. To replace the existing dict, #define USE_OPEN_DICT 2020-08-09 21:12:19 -07:00
Tim Wojtulewicz
a2a435360a Move all of the hashing classes/functions to zeek::detail namespace 2020-07-31 16:23:34 -04:00
Tim Wojtulewicz
bfab224d7c Move Reporter to zeek namespace 2020-07-31 16:22:41 -04:00
Tim Wojtulewicz
464efbe66a Move Dictionary/PDict, List/PList, and Queue/PQueue to zeek namespace 2020-06-30 21:12:26 -07:00
Jon Siwek
2d91f9d89f Merge remote-tracking branch 'origin/topic/timw/dict-cleanup'
* origin/topic/timw/dict-cleanup:
  A few minor cleanups in Dict
2020-04-14 15:46:03 -07:00
Tim Wojtulewicz
d4784f5525 A few minor cleanups in Dict 2020-04-13 13:39:17 -07:00
Tim Wojtulewicz
0a47588d0b The remaining nulls 2020-04-07 16:08:34 -07:00
Tim Wojtulewicz
fd5e15b116 The Great Embooleanating
A large number of functions had return values and/or arguments changed
to use ``bool`` types instead of ``int``.
2020-03-31 06:41:54 +00:00