Skip to content

Commit b279a90

Browse files
Marshall ClowMarshall Clow
Marshall Clow
authored and
Marshall Clow
committed
Fix off-by-one error in range-checking for 'at()'. thanks to DHilbrich for the bug report.
1 parent 854215e commit b279a90

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Diff for: include/boost/array.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ namespace boost {
183183

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

189189
};

Diff for: test/array6.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ namespace {
2727
const arr &caRef = get_c_array ( test_case );
2828
typename test_type::const_iterator iter = test_case.begin ();
2929
BOOST_CHECK ( &*iter == &caRef[0] );
30+
31+
// Confirm at() throws the std lib defined exception
32+
try {
33+
test_case.at( test_case.size());
34+
BOOST_CHECK(false);
35+
}
36+
catch ( const std::out_of_range & ) {}
37+
38+
try {
39+
test_case.at( test_case.size() + 1);
40+
BOOST_CHECK(false);
41+
}
42+
catch ( const std::out_of_range & ) {}
43+
44+
try {
45+
test_case.at( test_case.size() + 100);
46+
BOOST_CHECK(false);
47+
}
48+
catch ( const std::out_of_range & ) {}
3049
}
3150
}
3251

0 commit comments

Comments
 (0)