From 05eb181be2235d3db4dcb45a93ed94d2ef28c400 Mon Sep 17 00:00:00 2001 From: kaldoran <kaldoran@live.fr> Date: Mon, 27 Jun 2016 17:35:56 -0400 Subject: [PATCH] Pht : Fix out of range in isActiveBit function --- include/opendht/indexation/pht.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/opendht/indexation/pht.h b/include/opendht/indexation/pht.h index a5ab9b1a..caaa7e5b 100644 --- a/include/opendht/indexation/pht.h +++ b/include/opendht/indexation/pht.h @@ -52,8 +52,12 @@ struct Prefix { * @param pos : Pos of the needed bit * @return : true if the bit is at 1 * false otherwise + * @throw out_of_range Throw out of range if the bit at 'pos' does not exist */ bool isActiveBit(size_t pos) const { + if ( pos >= size_ ) + throw std::out_of_range("Can't detect active bit at pos, pos larger than prefix size or empty prefix"); + return ((this->content_[pos / 8] >> (7 - (pos % 8)) ) & 1) == 1; } -- GitLab