Skip to content
Snippets Groups Projects
Commit c8fcffbe authored by Simon Désaulniers's avatar Simon Désaulniers Committed by Adrien Béraud
Browse files

fix possible out of range error in Prefix ctor

parent 63c4eeb9
No related branches found
No related tags found
No related merge requests found
...@@ -28,10 +28,13 @@ struct Prefix { ...@@ -28,10 +28,13 @@ struct Prefix {
Prefix() {} Prefix() {}
Prefix(InfoHash h) : size_(h.size() * 8), content_(h.begin(), h.end()) {} Prefix(InfoHash h) : size_(h.size() * 8), content_(h.begin(), h.end()) {}
Prefix(const Blob& d) : size_(d.size()*8), content_(d) {} 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) { Prefix(const Prefix& p, size_t first) :
auto rem = first % 8; size_(std::min(first, p.content_.size()*8)),
content_(Blob(p.content_.begin(), p.content_.begin()+size_/8))
{
auto rem = size_ % 8;
if (rem) if (rem)
content_.push_back(p.content_[first/8] & (0xFF << (7 - rem))); content_.push_back(p.content_[size_/8] & (0xFF << (7 - rem)));
} }
Prefix getPrefix(ssize_t len) const { Prefix getPrefix(ssize_t len) const {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment