diff options
author | Evan Brown <ezb@google.com> | 2024-07-10 12:44:39 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-07-10 12:45:28 -0700 |
commit | 5b6285e7c5548adf74396650c473efb163363705 (patch) | |
tree | 969d74ba9f19d4a4b563de511aea870d629c926a /absl/base/internal/poison_test.cc | |
parent | bb50cad0adb77f6afdab1d50c093aae2b36d0522 (diff) | |
download | abseil-5b6285e7c5548adf74396650c473efb163363705.tar.gz abseil-5b6285e7c5548adf74396650c473efb163363705.tar.bz2 abseil-5b6285e7c5548adf74396650c473efb163363705.zip |
Roll forward poisoned pointer API and fix portability issues.
Also, return the middle of the poisoned block.
PiperOrigin-RevId: 651119057
Change-Id: Iae0fc3dcb40e32cd449f469d9b8d62c37f3773f4
Diffstat (limited to 'absl/base/internal/poison_test.cc')
-rw-r--r-- | absl/base/internal/poison_test.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/absl/base/internal/poison_test.cc b/absl/base/internal/poison_test.cc new file mode 100644 index 00000000..6596b454 --- /dev/null +++ b/absl/base/internal/poison_test.cc @@ -0,0 +1,41 @@ +// Copyright 2024 The Abseil Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/base/internal/poison.h" + +#include <iostream> + +#include "gtest/gtest.h" +#include "absl/base/config.h" + +namespace absl { +ABSL_NAMESPACE_BEGIN +namespace base_internal { +namespace { + +TEST(PoisonTest, CrashesOnDereference) { +#ifdef __ANDROID__ + GTEST_SKIP() << "On Android, poisoned pointer dereference times out instead " + "of crashing."; +#endif + int* poisoned_ptr = static_cast<int*>(get_poisoned_pointer()); + EXPECT_DEATH_IF_SUPPORTED(std::cout << *poisoned_ptr, ""); + EXPECT_DEATH_IF_SUPPORTED(std::cout << *(poisoned_ptr - 10), ""); + EXPECT_DEATH_IF_SUPPORTED(std::cout << *(poisoned_ptr + 10), ""); +} + +} // namespace +} // namespace base_internal +ABSL_NAMESPACE_END +} // namespace absl |