Skip to content

Commit 96839d6

Browse files
authored
Merge pull request #827 from RicoAntonioFelix/dev
statman.cpp: Perform bounds check in Statman::last_used
2 parents b9e45dc + 2586a43 commit 96839d6

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

src/util/statman.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18+
#include <iterator>
1819
#include <statman>
1920

2021
// Stat
@@ -76,15 +77,10 @@ Statman::Statman(uintptr_t start, Size_type num_bytes)
7677
}
7778

7879
Statman::Span_iterator Statman::last_used() {
79-
int i = 0;
80-
81-
for(auto it = stats_.begin(); it not_eq stats_.end(); ++it) {
82-
if(i == next_available_)
83-
return it;
84-
i++;
85-
}
86-
87-
return stats_.end();
80+
Expects(next_available_ <= stats_.size());
81+
auto it = stats_.begin();
82+
std::advance(it, next_available_);
83+
return it;
8884
}
8985

9086
Stat& Statman::create(const Stat::stat_type type, const std::string& name) {

0 commit comments

Comments
 (0)