]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Use size_t instead of unsigned int for the page size to prevent int overflows
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 14 Apr 2011 20:12:44 +0000 (14:12 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 14 Apr 2011 20:12:44 +0000 (14:12 -0600)
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.

src/ipc/mem/PagePool.cc
src/ipc/mem/PagePool.h

index 60aee9738c729caeb258ac69cfaf9cb59fdb28e9..5f270904f0d580ae6097693a6dcd068f0ba18fd0 100644 (file)
@@ -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)
index 7d45d3623f2b098de8f419932f0f6eeeda6f90e5..102ac1ce0b156741b6c866ef10b7710321d5b028 100644 (file)
@@ -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
     };