From: Alex Rousskov Date: Thu, 14 Apr 2011 20:12:44 +0000 (-0600) Subject: Use size_t instead of unsigned int for the page size to prevent int overflows X-Git-Tag: take06~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4140f17defa9657ff38cc778b0362dd20368cda3;p=thirdparty%2Fsquid.git Use size_t instead of unsigned int for the page size to prevent int overflows when computing the total segment size. Size_t is also more appropriate for memory object sizes, even though it is very unlikely that page sizes will get bigger than an int can hold. --- diff --git a/src/ipc/mem/PagePool.cc b/src/ipc/mem/PagePool.cc index 60aee9738c..5f270904f0 100644 --- a/src/ipc/mem/PagePool.cc +++ b/src/ipc/mem/PagePool.cc @@ -21,7 +21,7 @@ PageIndexId(String id) // Ipc::Mem::PagePool -Ipc::Mem::PagePool::PagePool(const String &id, const unsigned int capacity, const unsigned int pageSize): +Ipc::Mem::PagePool::PagePool(const String &id, const unsigned int capacity, const size_t pageSize): pageIndex(PageIndexId(id), capacity), shm(id.termedBuf()) { @@ -75,7 +75,7 @@ Ipc::Mem::PagePool::pageIdIsValid(const PageId &page) const static unsigned int LastPagePoolId = 0; -Ipc::Mem::PagePool::Shared::Shared(const unsigned int aCapacity, const unsigned int aPageSize): +Ipc::Mem::PagePool::Shared::Shared(const unsigned int aCapacity, size_t aPageSize): theId(++LastPagePoolId), theCapacity(aCapacity), thePageSize(aPageSize) { if (LastPagePoolId + 1 == 0) diff --git a/src/ipc/mem/PagePool.h b/src/ipc/mem/PagePool.h index 7d45d3623f..102ac1ce0b 100644 --- a/src/ipc/mem/PagePool.h +++ b/src/ipc/mem/PagePool.h @@ -21,12 +21,12 @@ class PageId; class PagePool { public: /// creates a new shared page pool that can hold up to capacity pages of pageSize size - PagePool(const String &id, const unsigned int capacity, const unsigned int pageSize); + PagePool(const String &id, const unsigned int capacity, const size_t pageSize); /// attaches to the identified shared page pool PagePool(const String &id); unsigned int capacity() const { return shared->theCapacity; } - unsigned int pageSize() const { return shared->thePageSize; } + size_t pageSize() const { return shared->thePageSize; } /// sets page ID and returns true unless no free pages are found bool get(PageId &page); @@ -39,11 +39,11 @@ private: inline bool pageIdIsValid(const PageId &page) const; struct Shared { - Shared(const unsigned int aCapacity, const unsigned int aPageSize); + Shared(const unsigned int aCapacity, const size_t aPageSize); const unsigned int theId; ///< pool id const unsigned int theCapacity; ///< number of pages in the pool - const unsigned int thePageSize; ///< page size + const size_t thePageSize; ///< page size char theBuf[]; ///< pages storage };