mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
fix possible out of range error in Prefix ctor
This commit is contained in:
1 parent
63c4eeb9c9
commit
c8fcffbe6b
1 file changed
+13
-10
@@ -28,10 +28,13 @@ struct Prefix {
|
||||
Prefix() {}
|
||||
Prefix(InfoHash h) : size_(h.size() * 8), content_(h.begin(), h.end()) {}
|
||||
Prefix(const Blob& d) : size_(d.size()*8), content_(d) {}
|
||||
Prefix(const Prefix& p, size_t first) : size_(first), content_(p.content_.begin(), p.content_.begin()+first/8) {
|
||||
auto rem = first % 8;
|
||||
if (rem)
|
||||
content_.push_back(p.content_[first/8] & (0xFF << (7 - rem)));
|
||||
Prefix(const Prefix& p, size_t first) :
|
||||
size_(std::min(first, p.content_.size()*8)),
|
||||
content_(Blob(p.content_.begin(), p.content_.begin()+size_/8))
|
||||
{
|
||||
auto rem = size_ % 8;
|
||||
if (rem)
|
||||
content_.push_back(p.content_[size_/8] & (0xFF << (7 - rem)));
|
||||
}
|
||||
|
||||
Prefix getPrefix(ssize_t len) const {
|
||||
@@ -50,12 +53,12 @@ struct Prefix {
|
||||
* @return The prefix of this sibling.
|
||||
*/
|
||||
Prefix getSibling() const {
|
||||
Prefix copy = *this;
|
||||
if (size_) {
|
||||
size_t last_bit = (8 - size_) % 8;
|
||||
copy.content_.back() ^= (1 << last_bit);
|
||||
}
|
||||
return copy;
|
||||
Prefix copy = *this;
|
||||
if (size_) {
|
||||
size_t last_bit = (8 - size_) % 8;
|
||||
copy.content_.back() ^= (1 << last_bit);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
InfoHash hash() const {
|
||||
|
||||
Reference in new issue
Block a user