Merge pull request #736 from TETYYS/message-limit-fix

Changed LimitedQueue::space() to signed value, eliminating underflows
This commit is contained in:
pajlada 2018-09-30 14:50:47 +00:00 committed by GitHub
commit d79a8b81b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,7 +32,7 @@ protected:
typedef std::shared_ptr<std::vector<Chunk>> ChunkVector; typedef std::shared_ptr<std::vector<Chunk>> ChunkVector;
public: public:
LimitedQueue(int limit = 1000) LimitedQueue(size_t limit = 1000)
: limit_(limit) : limit_(limit)
{ {
this->clear(); this->clear();
@ -106,7 +106,7 @@ public:
} }
// create new chunk for the first one // create new chunk for the first one
size_t offset = std::min(this->space(), items.size()); size_t offset = std::min(this->space(), static_cast<qsizetype>(items.size()));
Chunk newFirstChunk = std::make_shared<std::vector<T>>(); Chunk newFirstChunk = std::make_shared<std::vector<T>>();
newFirstChunk->resize(this->chunks_->front()->size() + offset); newFirstChunk->resize(this->chunks_->front()->size() + offset);
@ -214,7 +214,7 @@ public:
} }
private: private:
size_t space() qsizetype space()
{ {
size_t totalSize = 0; size_t totalSize = 0;
for (Chunk &chunk : *this->chunks_) { for (Chunk &chunk : *this->chunks_) {