diff options
author | Abseil Team <absl-team@google.com> | 2024-07-02 08:40:43 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-07-02 08:41:39 -0700 |
commit | 0d9c2fc763dd766b868665a302ff4526748c4b36 (patch) | |
tree | f036066c1f5149aa3061ff4203fe32ef37c3badb /absl/synchronization/internal/graphcycles.cc | |
parent | f36d33317ce3ca0a2212ffd264a26fd18e57a509 (diff) | |
download | abseil-0d9c2fc763dd766b868665a302ff4526748c4b36.tar.gz abseil-0d9c2fc763dd766b868665a302ff4526748c4b36.tar.bz2 abseil-0d9c2fc763dd766b868665a302ff4526748c4b36.zip |
Replace signed integer overflow, since that's undefined behavior, with unsigned integer overflow.
PiperOrigin-RevId: 648730502
Change-Id: I662c365c59be9e51f565fd215d284a96b7bd8743
Diffstat (limited to 'absl/synchronization/internal/graphcycles.cc')
-rw-r--r-- | absl/synchronization/internal/graphcycles.cc | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/absl/synchronization/internal/graphcycles.cc b/absl/synchronization/internal/graphcycles.cc index 61b4ec05..129067c1 100644 --- a/absl/synchronization/internal/graphcycles.cc +++ b/absl/synchronization/internal/graphcycles.cc @@ -211,7 +211,7 @@ class NodeSet { Vec<int32_t> table_; uint32_t occupied_; // Count of non-empty slots (includes deleted slots) - static uint32_t Hash(int32_t a) { return static_cast<uint32_t>(a * 41); } + static uint32_t Hash(int32_t a) { return static_cast<uint32_t>(a) * 41; } // Return index for storing v. May return an empty index or deleted index uint32_t FindIndex(int32_t v) const { @@ -365,6 +365,14 @@ static Node* FindNode(GraphCycles::Rep* rep, GraphId id) { return (n->version == NodeVersion(id)) ? n : nullptr; } +void GraphCycles::TestOnlyAddNodes(uint32_t n) { + uint32_t old_size = rep_->nodes_.size(); + rep_->nodes_.resize(n); + for (auto i = old_size; i < n; ++i) { + rep_->nodes_[i] = nullptr; + } +} + GraphCycles::GraphCycles() { InitArenaIfNecessary(); rep_ = new (base_internal::LowLevelAlloc::AllocWithArena(sizeof(Rep), arena)) @@ -373,6 +381,7 @@ GraphCycles::GraphCycles() { GraphCycles::~GraphCycles() { for (auto* node : rep_->nodes_) { + if (node == nullptr) { continue; } node->Node::~Node(); base_internal::LowLevelAlloc::Free(node); } |