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_test.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_test.cc')
-rw-r--r-- | absl/synchronization/internal/graphcycles_test.cc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/absl/synchronization/internal/graphcycles_test.cc b/absl/synchronization/internal/graphcycles_test.cc index 3c6ef798..47410aad 100644 --- a/absl/synchronization/internal/graphcycles_test.cc +++ b/absl/synchronization/internal/graphcycles_test.cc @@ -14,6 +14,7 @@ #include "absl/synchronization/internal/graphcycles.h" +#include <climits> #include <map> #include <random> #include <unordered_set> @@ -458,6 +459,24 @@ TEST_F(GraphCyclesTest, ManyEdges) { CheckInvariants(g_); } +TEST(GraphCycles, IntegerOverflow) { + GraphCycles graph_cycles; + char *buf = (char *)nullptr; + GraphId prev_id = graph_cycles.GetId(buf); + buf += 1; + GraphId id = graph_cycles.GetId(buf); + ASSERT_TRUE(graph_cycles.InsertEdge(prev_id, id)); + + // INT_MAX / 40 is enough to cause an overflow when multiplied by 41. + graph_cycles.TestOnlyAddNodes(INT_MAX / 40); + + buf += 1; + GraphId newid = graph_cycles.GetId(buf); + graph_cycles.HasEdge(prev_id, newid); + + graph_cycles.RemoveNode(buf); +} + } // namespace synchronization_internal ABSL_NAMESPACE_END } // namespace absl |