-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++][hardening] Add hardening assertions to std::deque #79397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <deque> | ||
|
||
// Test hardening assertions for std::deque. | ||
|
||
// REQUIRES: has-unix-headers | ||
// UNSUPPORTED: libcpp-hardening-mode=none | ||
// UNSUPPORTED: c++03 | ||
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing | ||
|
||
#include <deque> | ||
|
||
#include "check_assertion.h" | ||
|
||
int main(int, char**) { | ||
std::deque<int> c; | ||
TEST_LIBCPP_ASSERT_FAILURE(c.front(), "deque::front called on an empty deque"); | ||
TEST_LIBCPP_ASSERT_FAILURE(c.back(), "deque::back called on an empty deque"); | ||
TEST_LIBCPP_ASSERT_FAILURE(c[0], "deque::operator[] index out of bounds"); | ||
TEST_LIBCPP_ASSERT_FAILURE(c.pop_front(), "deque::pop_front called on an empty deque"); | ||
TEST_LIBCPP_ASSERT_FAILURE(c.pop_back(), "deque::pop_back called on an empty deque"); | ||
|
||
// Repeat the test with a const reference to test the const overloads. | ||
{ | ||
const std::deque<int>& cc = c; | ||
TEST_LIBCPP_ASSERT_FAILURE(cc.front(), "deque::front called on an empty deque"); | ||
TEST_LIBCPP_ASSERT_FAILURE(cc.back(), "deque::back called on an empty deque"); | ||
TEST_LIBCPP_ASSERT_FAILURE(cc[0], "deque::operator[] index out of bounds"); | ||
} | ||
|
||
c.push_back(1); | ||
c.push_back(2); | ||
c.push_back(3); | ||
TEST_LIBCPP_ASSERT_FAILURE(c[3], "deque::operator[] index out of bounds"); | ||
TEST_LIBCPP_ASSERT_FAILURE(c[100], "deque::operator[] index out of bounds"); | ||
|
||
// Repeat the test with a const reference to test the const overloads. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test cases above are also on a const reference, aren't they? Are we missing mutable overloads then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nevermind, sorry, I was looking at the front() ones but this is []. |
||
{ | ||
const std::deque<int>& cc = c; | ||
TEST_LIBCPP_ASSERT_FAILURE(cc[3], "deque::operator[] index out of bounds"); | ||
TEST_LIBCPP_ASSERT_FAILURE(cc[100], "deque::operator[] index out of bounds"); | ||
} | ||
|
||
TEST_LIBCPP_ASSERT_FAILURE(c.erase(c.end()), "deque::erase(iterator) called with a non-dereferenceable iterator"); | ||
TEST_LIBCPP_ASSERT_FAILURE( | ||
c.erase(c.begin() + 1, c.begin()), "deque::erase(first, last) called with an invalid range"); | ||
|
||
return 0; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.