Changed LimitedQueue::space() to signed value, eliminating underflows

This commit is contained in:
tetyys 2018-09-26 22:21:38 +03:00
parent 4c5a0472cd
commit 45d0bd6299

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_) {