Fix off-by-one error in range-checking for 'at()'. thanks to DHilbrich for the bug report.

This commit is contained in:
Marshall Clow
2019-02-07 07:52:11 -08:00
parent 854215e54c
commit b279a9005b
2 changed files with 20 additions and 1 deletions

View File

@ -183,7 +183,7 @@ namespace boost {
// check range (may be private because it is static)
static BOOST_CONSTEXPR bool rangecheck (size_type i) {
return i > size() ? boost::throw_exception(std::out_of_range ("array<>: index out of range")), true : true;
return i >= size() ? boost::throw_exception(std::out_of_range ("array<>: index out of range")), true : true;
}
};

View File

@ -27,6 +27,25 @@ namespace {
const arr &caRef = get_c_array ( test_case );
typename test_type::const_iterator iter = test_case.begin ();
BOOST_CHECK ( &*iter == &caRef[0] );
// Confirm at() throws the std lib defined exception
try {
test_case.at( test_case.size());
BOOST_CHECK(false);
}
catch ( const std::out_of_range & ) {}
try {
test_case.at( test_case.size() + 1);
BOOST_CHECK(false);
}
catch ( const std::out_of_range & ) {}
try {
test_case.at( test_case.size() + 100);
BOOST_CHECK(false);
}
catch ( const std::out_of_range & ) {}
}
}