]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix GCC v13 LTO build [-Walloc-size-larger-than=] (#1929)
authorJulien <juju4@users.noreply.github.com>
Sun, 23 Feb 2025 20:06:06 +0000 (20:06 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sun, 23 Feb 2025 23:16:09 +0000 (23:16 +0000)
    store/Disks.cc:690: error: argument 1 value 18446744073709551615
        exceeds maximum object size 9223372036854775807
        [-Werror=alloc-size-larger-than=]
    const auto tmp = new SwapDir::Pointer[swap->n_allocated];

    pconn.cc:43:53: error: argument 1 value 18446744073709551615 ...
    theList_ = new Comm::ConnectionPointer[capacity_];

Tested on Ubuntu 24.04 and GCC v13.2.0.

23 files changed:
CONTRIBUTORS
src/DiskIO/DiskThreads/DiskThreads.h
src/DiskIO/DiskThreads/aiops.cc
src/DiskIO/DiskThreads/async_io.cc
src/SquidConfig.h
src/auth/SchemeConfig.cc
src/auth/SchemeConfig.h
src/auth/basic/Config.cc
src/auth/basic/Config.h
src/auth/digest/Config.cc
src/auth/digest/Config.h
src/fs/rock/RockSwapDir.cc
src/fs/ufs/UFSSwapDir.cc
src/fs/ufs/UFSSwapDir.h
src/pconn.cc
src/pconn.h
src/store.cc
src/store/Disks.cc
src/store/Disks.h
src/store_rebuild.cc
src/tests/testStoreController.cc
src/tests/testStoreHashIndex.cc
src/unlinkd.cc

index d69ba5cb61ce778cf8c092c50a7226b8bd314a6f..d9156cae0f22bce0c365d8efd25a7bc753b29dfc 100644 (file)
@@ -288,6 +288,7 @@ Thank you!
     JPP <jpp1@frws.com>
     Juan <jdsq12@yahoo.es>
     Juerg Michel
+    Juju4 <juju4@users.noreply.github.com>
     Julien Pinon <jpinon@olfeo.com>
     Karl Benoit <karl.isatwork@gmail.com>
     Khalid Abdullah <khalidcomilla58@gmail.com>
index 1dbe232849c36414804f2b8f646dbf0556113825..f968ab76fa7d442d6b92a3d097a8ec71543ffda8 100644 (file)
@@ -113,7 +113,7 @@ void aioRead(int, off_t offset, size_t size, AIOCB *, void *);
 
 void aioStat(char *, struct stat *, AIOCB *, void *);
 void aioUnlink(const char *, AIOCB *, void *);
-int aioQueueSize(void);
+size_t aioQueueSize(void);
 
 #include "DiskIO/DiskFile.h"
 
index 077e5f21e51af081eead0040cd9e933e0a8d28aa..8eab4af24a64d1efd87e579838b3cf0399263524 100644 (file)
@@ -118,7 +118,7 @@ static Mem::Allocator *squidaio_small_bufs = nullptr; /* 4K */
 static Mem::Allocator *squidaio_tiny_bufs = nullptr; /* 2K */
 static Mem::Allocator *squidaio_micro_bufs = nullptr; /* 128K */
 
-static int request_queue_len = 0;
+static size_t request_queue_len = 0;
 static Mem::Allocator *squidaio_request_pool = nullptr;
 static Mem::Allocator *squidaio_thread_pool = nullptr;
 static squidaio_request_queue_t request_queue;
@@ -215,7 +215,6 @@ squidaio_xstrfree(char *str)
 void
 squidaio_init(void)
 {
-    int i;
     squidaio_thread_t *threadp;
 
     if (squidaio_initialised)
@@ -294,7 +293,7 @@ squidaio_init(void)
 
     assert(NUMTHREADS != 0);
 
-    for (i = 0; i < NUMTHREADS; ++i) {
+    for (size_t i = 0; i < NUMTHREADS; ++i) {
         threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc();
         threadp->status = _THREAD_STARTING;
         threadp->current_req = nullptr;
@@ -515,7 +514,7 @@ squidaio_queue_request(squidaio_request_t * request)
     /* Warn if out of threads */
     if (request_queue_len > MAGIC1) {
         static int last_warn = 0;
-        static int queue_high, queue_low;
+        static size_t queue_high, queue_low;
 
         if (high_start == 0) {
             high_start = squid_curtime;
@@ -999,7 +998,6 @@ void
 squidaio_stats(StoreEntry * sentry)
 {
     squidaio_thread_t *threadp;
-    int i;
 
     if (!squidaio_initialised)
         return;
@@ -1010,8 +1008,8 @@ squidaio_stats(StoreEntry * sentry)
 
     threadp = threads;
 
-    for (i = 0; i < NUMTHREADS; ++i) {
-        storeAppendPrintf(sentry, "%i\t0x%lx\t%ld\n", i + 1, (unsigned long)threadp->thread, threadp->requests);
+    for (size_t i = 0; i < NUMTHREADS; ++i) {
+        storeAppendPrintf(sentry, "%zu\t0x%lx\t%ld\n", i + 1, (unsigned long)threadp->thread, threadp->requests);
         threadp = threadp->next;
     }
 }
index d820cb1790d66f562be94c053153233965ada2d1..f66cb1f156cb21807ef54f1d835e66b242f51fe8 100644 (file)
@@ -195,7 +195,7 @@ aioUnlink(const char *path, AIOCB * callback, void *callback_data)
     dlinkAdd(ctrlp, &ctrlp->node, &used_list);
 }               /* aioUnlink */
 
-int
+size_t
 aioQueueSize(void)
 {
     return squidaio_ctrl_t::UseCount();
index a79a6cdc4fc040bb3f8fb901d6b5a39a229b5d3d..548ea41673c8239c4fb55ee133674bbf52f36894 100644 (file)
@@ -66,8 +66,8 @@ public:
     ~DiskConfig() { delete[] swapDirs; }
 
     RefCount<SwapDir> *swapDirs = nullptr;
-    int n_allocated = 0;
-    int n_configured = 0;
+    size_t n_allocated = 0;
+    size_t n_configured = 0;
     /// number of disk processes required to support all cache_dirs
     int n_strands = 0;
 };
index ce87611ffe09bc8d64375c92df015d01149e6c47..b4b49788c10cc3762340b067d46b2beaefaaf083 100644 (file)
@@ -81,7 +81,7 @@ Auth::SchemeConfig::registerWithCacheManager(void)
 {}
 
 void
-Auth::SchemeConfig::parse(Auth::SchemeConfig * scheme, int, char *param_str)
+Auth::SchemeConfig::parse(Auth::SchemeConfig * scheme, size_t, char *param_str)
 {
     if (strcmp(param_str, "program") == 0) {
         if (authenticateProgram)
index e7046d5d8b3dd19681b8a62aa632f778a75e1e48..0e0aa0d9ccc3ba3ff3f1ef691bca605ab14f24d3 100644 (file)
@@ -119,7 +119,7 @@ public:
     virtual void registerWithCacheManager(void);
 
     /** parse config options */
-    virtual void parse(SchemeConfig *, int, char *);
+    virtual void parse(SchemeConfig *, size_t, char *);
 
     /** the http string id */
     virtual const char * type() const = 0;
index 7154c5375e4f1037f4f0e27de11b5773a2218fea..65836f72deb8909ec85bc259e53714333c44e70e 100644 (file)
@@ -135,7 +135,7 @@ Auth::Basic::Config::Config() :
 }
 
 void
-Auth::Basic::Config::parse(Auth::SchemeConfig * scheme, int n_configured, char *param_str)
+Auth::Basic::Config::parse(Auth::SchemeConfig * scheme, size_t n_configured, char *param_str)
 {
     if (strcmp(param_str, "credentialsttl") == 0) {
         parse_time_t(&credentialsTTL);
index e7f2f0f850c49fe511d7ca117ab831bf3dd34a10..e8015de6230df41d810a9601333c2b079e3c9c74 100644 (file)
@@ -34,7 +34,7 @@ public:
     bool dump(StoreEntry *, const char *, Auth::SchemeConfig *) const override;
     void fixHeader(Auth::UserRequest::Pointer, HttpReply *, Http::HdrType, HttpRequest *) override;
     void init(Auth::SchemeConfig *) override;
-    void parse(Auth::SchemeConfig *, int, char *) override;
+    void parse(Auth::SchemeConfig *, size_t, char *) override;
     void decode(char const *httpAuthHeader, Auth::UserRequest::Pointer);
     void registerWithCacheManager(void) override;
     const char * type() const override;
index a412521086124730c43b9e407649b066cb914609..38e2da34943f653f9d47610700be08c632711a0b 100644 (file)
@@ -577,7 +577,7 @@ Auth::Digest::Config::Config() :
 {}
 
 void
-Auth::Digest::Config::parse(Auth::SchemeConfig * scheme, int n_configured, char *param_str)
+Auth::Digest::Config::parse(Auth::SchemeConfig * scheme, size_t n_configured, char *param_str)
 {
     if (strcmp(param_str, "nonce_garbage_interval") == 0) {
         parse_time_t(&nonceGCInterval);
index b2cc949f1b2c549747336ea15815ea5a38e0c598..1ad95d9bb5888908a3fb2b3195430571a1def266 100644 (file)
@@ -81,7 +81,7 @@ public:
     bool dump(StoreEntry *, const char *, Auth::SchemeConfig *) const override;
     void fixHeader(Auth::UserRequest::Pointer, HttpReply *, Http::HdrType, HttpRequest *) override;
     void init(Auth::SchemeConfig *) override;
-    void parse(Auth::SchemeConfig *, int, char *) override;
+    void parse(Auth::SchemeConfig *, size_t, char *) override;
     void registerWithCacheManager(void) override;
     const char * type() const override;
 
index 20426ca4d2f272dadff44a9f7e0c425946dd529c..ca9ef19343967f6d457cecbe0f6eda565322d8e2 100644 (file)
@@ -1118,7 +1118,7 @@ DefineRunnerRegistratorIn(Rock, SwapDirRr);
 void Rock::SwapDirRr::create()
 {
     Must(mapOwners.empty() && freeSlotsOwners.empty());
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         if (const Rock::SwapDir *const sd = dynamic_cast<Rock::SwapDir *>(INDEXSD(i))) {
             rebuildStatsOwners.push_back(Rebuild::Stats::Init(*sd));
 
index 8dd64598718a30ab19d740d1b6fa6b9fe0fe4dce..f005d445e12819349d33227fb66c513e3cbd63f4 100644 (file)
@@ -37,7 +37,7 @@
 #include <sys/stat.h>
 #endif
 
-int Fs::Ufs::UFSSwapDir::NumberOfUFSDirs = 0;
+size_t Fs::Ufs::UFSSwapDir::NumberOfUFSDirs = 0;
 int *Fs::Ufs::UFSSwapDir::UFSDirToGlobalDirMapping = nullptr;
 
 class UFSCleanLog : public SwapDir::CleanLog
@@ -757,8 +757,8 @@ Fs::Ufs::UFSSwapDir::closeLog()
     if (swaplog_fd < 0) /* not open */
         return;
 
+    assert(NumberOfUFSDirs > 0);
     --NumberOfUFSDirs;
-    assert(NumberOfUFSDirs >= 0);
     if (!NumberOfUFSDirs)
         safe_free(UFSDirToGlobalDirMapping);
 
@@ -1039,9 +1039,8 @@ int
 Fs::Ufs::UFSSwapDir::HandleCleanEvent()
 {
     static int swap_index = 0;
-    int i;
     int j = 0;
-    int n = 0;
+    size_t n = 0;
 
     if (!NumberOfUFSDirs)
         return 0; // probably in the middle of reconfiguration
@@ -1054,7 +1053,7 @@ Fs::Ufs::UFSSwapDir::HandleCleanEvent()
          */
         UFSDirToGlobalDirMapping = (int *)xcalloc(NumberOfUFSDirs, sizeof(*UFSDirToGlobalDirMapping));
 
-        for (i = 0, n = 0; i < Config.cacheSwap.n_configured; ++i) {
+        for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
             /* This is bogus, the controller should just clean each instance once */
             sd = dynamic_cast <SwapDir *>(INDEXSD(i));
 
@@ -1117,7 +1116,8 @@ Fs::Ufs::UFSSwapDir::FilenoBelongsHere(int fn, int F0, int F1, int F2)
     int D1, D2;
     int L1, L2;
     int filn = fn;
-    assert(F0 < Config.cacheSwap.n_configured);
+    assert(F0 >= 0);
+    assert(static_cast<size_t>(F0) < Config.cacheSwap.n_configured);
     assert (UFSSwapDir::IsUFSDir (dynamic_cast<SwapDir *>(INDEXSD(F0))));
     UFSSwapDir *sd = dynamic_cast<UFSSwapDir *>(INDEXSD(F0));
 
index ee47f635a2bb689c77594fb95e6e6b48c0d2d84c..3df03f47e777a0b5a0fdb71ed3b5af16e72ca9b1 100644 (file)
@@ -123,7 +123,7 @@ protected:
 
 private:
     void parseSizeL1L2();
-    static int NumberOfUFSDirs;
+    static size_t NumberOfUFSDirs;
     static int * UFSDirToGlobalDirMapping;
     bool pathIsDirectory(const char *path)const;
     int swaplog_fd;
index 45adde1a3d7f9ac64a7f4891415a5e7aaec66480..db943ccec346b16ea212b8fc2fdcf36b64f4e0c4 100644 (file)
@@ -73,7 +73,8 @@ IdleConnList::~IdleConnList()
 int
 IdleConnList::findIndexOf(const Comm::ConnectionPointer &conn) const
 {
-    for (int index = size_ - 1; index >= 0; --index) {
+    for (auto right = size_; right > 0; --right) {
+        const auto index = right - 1;
         if (conn->fd == theList_[index]->fd) {
             debugs(48, 3, "found " << conn << " at index " << index);
             return index;
@@ -89,10 +90,11 @@ IdleConnList::findIndexOf(const Comm::ConnectionPointer &conn) const
  * \retval false The index is not an in-use entry.
  */
 bool
-IdleConnList::removeAt(int index)
+IdleConnList::removeAt(size_t index)
 {
-    if (index < 0 || index >= size_)
+    if (index >= size_)
         return false;
+    assert(size_ > 0);
 
     // shuffle the remaining entries to fill the new gap.
     for (; index < size_ - 1; ++index)
@@ -112,12 +114,12 @@ IdleConnList::removeAt(int index)
 
 // almost a duplicate of removeFD. But drops multiple entries.
 void
-IdleConnList::closeN(size_t n)
+IdleConnList::closeN(const size_t n)
 {
     if (n < 1) {
         debugs(48, 2, "Nothing to do.");
         return;
-    } else if (n >= (size_t)size_) {
+    } else if (n >= size_) {
         debugs(48, 2, "Closing all entries.");
         while (size_ > 0) {
             const Comm::ConnectionPointer conn = theList_[--size_];
@@ -141,11 +143,11 @@ IdleConnList::closeN(size_t n)
                 parent_->noteConnectionRemoved();
         }
         // shuffle the list N down.
-        for (index = 0; index < (size_t)size_ - n; ++index) {
+        for (index = 0; index < size_ - n; ++index) {
             theList_[index] = theList_[index + n];
         }
         // ensure the last N entries are unset
-        while (index < ((size_t)size_)) {
+        while (index < size_) {
             theList_[index] = nullptr;
             ++index;
         }
@@ -174,7 +176,7 @@ IdleConnList::push(const Comm::ConnectionPointer &conn)
         capacity_ <<= 1;
         const Comm::ConnectionPointer *oldList = theList_;
         theList_ = new Comm::ConnectionPointer[capacity_];
-        for (int index = 0; index < size_; ++index)
+        for (size_t index = 0; index < size_; ++index)
             theList_[index] = oldList[index];
 
         delete[] oldList;
@@ -214,7 +216,8 @@ IdleConnList::isAvailable(int i) const
 Comm::ConnectionPointer
 IdleConnList::pop()
 {
-    for (int i=size_-1; i>=0; --i) {
+    for (auto right = size_; right > 0; --right) {
+        const auto i = right - 1;
 
         if (!isAvailable(i))
             continue;
@@ -252,7 +255,8 @@ IdleConnList::findUseable(const Comm::ConnectionPointer &aKey)
     const bool keyCheckAddr = !aKey->local.isAnyAddr();
     const bool keyCheckPort = aKey->local.port() > 0;
 
-    for (int i=size_-1; i>=0; --i) {
+    for (auto right = size_; right > 0; --right) {
+        const auto i = right - 1;
 
         if (!isAvailable(i))
             continue;
index cd206b12d48979caaa84e76d460cdf3248422634..4cb9fb22b29aa291d67895919dd4c04524022fbb 100644 (file)
@@ -59,14 +59,16 @@ public:
 
     void clearHandlers(const Comm::ConnectionPointer &conn);
 
+    // TODO: Upgrade to return size_t
     int count() const { return size_; }
+
     void closeN(size_t count);
 
     // IndependentRunner API
     void endingShutdown() override;
 private:
     bool isAvailable(int i) const;
-    bool removeAt(int index);
+    bool removeAt(size_t index);
     int findIndexOf(const Comm::ConnectionPointer &conn) const;
     void findAndClose(const Comm::ConnectionPointer &conn);
     static IOCB Read;
@@ -81,9 +83,9 @@ private:
     Comm::ConnectionPointer *theList_;
 
     /// Number of entries theList can currently hold without re-allocating (capacity).
-    int capacity_;
+    size_t capacity_;
     ///< Number of in-use entries in theList
-    int size_;
+    size_t size_;
 
     /** The pool containing this sub-list.
      * The parent performs all stats accounting, and
index 2adaf5c3c64f89773894b7590201899718b227d8..51230dcbf1eae162bb58f0fc771dc43cdd306b86 100644 (file)
@@ -1966,7 +1966,7 @@ StoreEntry::checkDisk() const
             Must(swap_status == SWAPOUT_NONE);
         } else {
             Must(swap_filen >= 0);
-            Must(swap_dirn < Config.cacheSwap.n_configured);
+            Must(static_cast<size_t>(swap_dirn) < Config.cacheSwap.n_configured);
             if (swapoutFailed()) {
                 Must(EBIT_TEST(flags, RELEASE_REQUEST));
             } else {
index b25ad253e5806dcb5cdcf93058390b321b3ba579..47ecbc2ef29ceafdc5ca5fc09a2f5ff8d54eb542 100644 (file)
@@ -55,9 +55,8 @@ objectSizeForDirSelection(const StoreEntry &entry)
 
 /// TODO: Remove when cache_dir-iterating functions are converted to Disks methods
 static SwapDir &
-SwapDirByIndex(const int i)
+SwapDirByIndex(const size_t i)
 {
-    assert(i >= 0);
     assert(i < Config.cacheSwap.n_allocated);
     const auto sd = INDEXSD(i);
     assert(sd);
@@ -76,12 +75,12 @@ storeDirSelectSwapDirRoundRobin(const StoreEntry * e)
 
     // Increment the first candidate once per selection (not once per
     // iteration) to reduce bias when some disk(s) attract more entries.
-    static int firstCandidate = 0;
+    static size_t firstCandidate = 0;
     if (++firstCandidate >= Config.cacheSwap.n_configured)
         firstCandidate = 0;
 
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
-        const int dirn = (firstCandidate + i) % Config.cacheSwap.n_configured;
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
+        const auto dirn = (firstCandidate + i) % Config.cacheSwap.n_configured;
         auto &dir = SwapDirByIndex(dirn);
 
         int load = 0;
@@ -119,11 +118,10 @@ storeDirSelectSwapDirLeastLoad(const StoreEntry * e)
     int least_load = INT_MAX;
     int load;
     SwapDir *selectedDir = nullptr;
-    int i;
 
     const int64_t objsize = objectSizeForDirSelection(*e);
 
-    for (i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         auto &sd = SwapDirByIndex(i);
         sd.flags.selected = false;
 
@@ -174,13 +172,13 @@ Store::Disks::Disks():
 }
 
 SwapDir *
-Store::Disks::store(int const x) const
+Store::Disks::store(const size_t x) const
 {
     return &SwapDirByIndex(x);
 }
 
 SwapDir &
-Store::Disks::Dir(const int i)
+Store::Disks::Dir(const size_t i)
 {
     return SwapDirByIndex(i);
 }
@@ -190,12 +188,12 @@ Store::Disks::callback()
 {
     int result = 0;
     int j;
-    static int ndir = 0;
+    static size_t ndir = 0;
 
     do {
         j = 0;
 
-        for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+        for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
             if (ndir >= Config.cacheSwap.n_configured)
                 ndir = ndir % Config.cacheSwap.n_configured;
 
@@ -224,7 +222,7 @@ Store::Disks::create()
         debugs(0, DBG_PARSE_NOTE(DBG_CRITICAL), "No cache_dir stores are configured.");
     }
 
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         if (Dir(i).active())
             store(i)->create();
     }
@@ -233,12 +231,12 @@ Store::Disks::create()
 StoreEntry *
 Store::Disks::get(const cache_key *key)
 {
-    if (const int cacheDirs = Config.cacheSwap.n_configured) {
+    if (const auto cacheDirs = Config.cacheSwap.n_configured) {
         // ask each cache_dir until the entry is found; use static starting
         // point to avoid asking the same subset of disks more often
         // TODO: coordinate with put() to be able to guess the right disk often
-        static int idx = 0;
-        for (int n = 0; n < cacheDirs; ++n) {
+        static size_t idx = 0;
+        for (size_t n = 0; n < cacheDirs; ++n) {
             idx = (idx + 1) % cacheDirs;
             auto &sd = Dir(idx);
             if (!sd.active())
@@ -289,7 +287,7 @@ Store::Disks::init()
     // level is decremented in each corresponding storeRebuildComplete() call.
     StoreController::store_dirs_rebuilding += Config.cacheSwap.n_configured;
 
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         /* this starts a search of the store dirs, loading their
          * index. under the new Store api this should be
          * driven by the StoreHashIndex, not by each store.
@@ -324,7 +322,7 @@ Store::Disks::maxSize() const
 {
     uint64_t result = 0;
 
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         if (Dir(i).doReportStat())
             result += store(i)->maxSize();
     }
@@ -337,7 +335,7 @@ Store::Disks::minSize() const
 {
     uint64_t result = 0;
 
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         if (Dir(i).doReportStat())
             result += store(i)->minSize();
     }
@@ -350,7 +348,7 @@ Store::Disks::currentSize() const
 {
     uint64_t result = 0;
 
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         if (Dir(i).doReportStat())
             result += store(i)->currentSize();
     }
@@ -363,7 +361,7 @@ Store::Disks::currentCount() const
 {
     uint64_t result = 0;
 
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         if (Dir(i).doReportStat())
             result += store(i)->currentCount();
     }
@@ -389,7 +387,7 @@ Store::Disks::configure()
 
     Config.cacheSwap.n_strands = 0;
 
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         auto &disk = Dir(i);
         if (disk.needsDiskStrand()) {
             assert(InDaemonMode());
@@ -433,7 +431,7 @@ Store::Disks::Parse(DiskConfig &swap)
 
     // check for the existing cache_dir
     // XXX: This code mistreats duplicated cache_dir entries (that should be fatal).
-    for (int i = 0; i < swap.n_configured; ++i) {
+    for (size_t i = 0; i < swap.n_configured; ++i) {
         auto &disk = Dir(i);
         if ((strcasecmp(pathStr, disk.path)) == 0) {
             /* this is specific to on-fs Stores. The right
@@ -453,7 +451,7 @@ Store::Disks::Parse(DiskConfig &swap)
         }
     }
 
-    const int cacheDirCountLimit = 64; // StoreEntry::swap_dirn is a signed 7-bit integer
+    const size_t cacheDirCountLimit = 64; // StoreEntry::swap_dirn is a signed 7-bit integer
     if (swap.n_configured >= cacheDirCountLimit)
         throw TextException(ToSBuf("Squid cannot handle more than ", cacheDirCountLimit, " cache_dir directives"), Here());
 
@@ -468,7 +466,7 @@ Store::Disks::Parse(DiskConfig &swap)
 void
 Store::Disks::Dump(const DiskConfig &swap, StoreEntry &entry, const char *name)
 {
-    for (int i = 0; i < swap.n_configured; ++i) {
+    for (size_t i = 0; i < swap.n_configured; ++i) {
         const auto &disk = Dir(i);
         storeAppendPrintf(&entry, "%s %s %s", name, disk.type(), disk.path);
         disk.dump(entry);
@@ -517,7 +515,7 @@ void
 Store::Disks::getStats(StoreInfoStats &stats) const
 {
     // accumulate per-disk cache stats
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         StoreInfoStats dirStats;
         store(i)->getStats(dirStats);
         stats += dirStats;
@@ -532,11 +530,9 @@ Store::Disks::getStats(StoreInfoStats &stats) const
 void
 Store::Disks::stat(StoreEntry & output) const
 {
-    int i;
-
     /* Now go through each store, calling its stat routine */
 
-    for (i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         storeAppendPrintf(&output, "\n");
         store(i)->stat(output);
     }
@@ -564,10 +560,9 @@ Store::Disks::updateHeaders(StoreEntry *e)
 void
 Store::Disks::maintain()
 {
-    int i;
     /* walk each fs */
 
-    for (i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         /* XXX FixMe: This should be done "in parallel" on the different
          * cache_dirs, not one at a time.
          */
@@ -579,7 +574,7 @@ Store::Disks::maintain()
 void
 Store::Disks::sync()
 {
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i)
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i)
         store(i)->sync();
 }
 
@@ -603,7 +598,7 @@ Store::Disks::evictCached(StoreEntry &e) {
 void
 Store::Disks::evictIfFound(const cache_key *key)
 {
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         if (Dir(i).active())
             Dir(i).evictIfFound(key);
     }
@@ -615,12 +610,12 @@ Store::Disks::anchorToCache(StoreEntry &entry)
     if (entry.hasDisk())
         return true; // already anchored
 
-    if (const int cacheDirs = Config.cacheSwap.n_configured) {
+    if (const size_t cacheDirs = Config.cacheSwap.n_configured) {
         // ask each cache_dir until the entry is found; use static starting
         // point to avoid asking the same subset of disks more often
         // TODO: coordinate with put() to be able to guess the right disk often
-        static int idx = 0;
-        for (int n = 0; n < cacheDirs; ++n) {
+        static size_t idx = 0;
+        for (size_t n = 0; n < cacheDirs; ++n) {
             idx = (idx + 1) % cacheDirs;
             SwapDir &sd = Dir(idx);
             if (!sd.active())
@@ -648,7 +643,7 @@ Store::Disks::updateAnchored(StoreEntry &entry)
 bool
 Store::Disks::SmpAware()
 {
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         // A mix is not supported, but we conservatively check every
         // dir because features like collapsed revalidation should
         // currently be disabled if any dir is SMP-aware
@@ -667,7 +662,7 @@ Store::Disks::SelectSwapDir(const StoreEntry *e)
 bool
 Store::Disks::hasReadableEntry(const StoreEntry &e) const
 {
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i)
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i)
         if (Dir(i).active() && Dir(i).hasReadableEntry(e))
             return true;
     return false;
@@ -676,14 +671,14 @@ Store::Disks::hasReadableEntry(const StoreEntry &e) const
 void
 storeDirOpenSwapLogs()
 {
-    for (int dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
+    for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
         SwapDirByIndex(dirn).openLog();
 }
 
 void
 storeDirCloseSwapLogs()
 {
-    for (int dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
+    for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
         SwapDirByIndex(dirn).closeLog();
 }
 
@@ -704,7 +699,6 @@ storeDirWriteCleanLogs(int reopen)
 
     struct timeval start;
     double dt;
-    int dirn;
     int notdone = 1;
 
     // Check for store_dirs_rebuilding because fatal() often calls us in early
@@ -720,7 +714,7 @@ storeDirWriteCleanLogs(int reopen)
     getCurrentTime();
     start = current_time;
 
-    for (dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn) {
+    for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn) {
         auto &sd = SwapDirByIndex(dirn);
 
         if (sd.writeCleanStart() < 0) {
@@ -737,7 +731,7 @@ storeDirWriteCleanLogs(int reopen)
     while (notdone) {
         notdone = 0;
 
-        for (dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn) {
+        for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn) {
             auto &sd = SwapDirByIndex(dirn);
 
             if (!sd.cleanLog)
@@ -764,7 +758,7 @@ storeDirWriteCleanLogs(int reopen)
     }
 
     /* Flush */
-    for (dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
+    for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
         SwapDirByIndex(dirn).writeCleanDone();
 
     if (reopen)
@@ -794,7 +788,7 @@ allocate_new_swapdir(Store::DiskConfig &swap)
     if (swap.n_allocated == swap.n_configured) {
         swap.n_allocated <<= 1;
         const auto tmp = new SwapDir::Pointer[swap.n_allocated];
-        for (int i = 0; i < swap.n_configured; ++i) {
+        for (size_t i = 0; i < swap.n_configured; ++i) {
             tmp[i] = swap.swapDirs[i];
         }
         delete[] swap.swapDirs;
index 9e9849d675c4ba7ad7ea5cc29dbd10c12d1f4f7f..d6f2efdaeba76172a6e88db821a39befc843e115 100644 (file)
@@ -60,8 +60,8 @@ public:
 
 private:
     /* migration logic */
-    SwapDir *store(int const x) const;
-    static SwapDir &Dir(int const idx);
+    SwapDir *store(size_t index) const;
+    static SwapDir &Dir(size_t index);
 
     int64_t largestMinimumObjectSize; ///< maximum of all Disk::minObjectSize()s
     int64_t largestMaximumObjectSize; ///< maximum of all Disk::maxObjectSize()s
index fa0877d80a57115400a082260a796de371515a50..981e86bc64c66b0480fbe458eb525463dc295991 100644 (file)
@@ -211,16 +211,18 @@ storeRebuildStart(void)
  * progress.
  */
 void
-storeRebuildProgress(int sd_index, int total, int sofar)
+storeRebuildProgress(const int sd_index_raw, const int total, const int sofar)
 {
     static time_t last_report = 0;
     // TODO: Switch to int64_t and fix handling of unknown totals.
     double n = 0.0;
     double d = 0.0;
 
-    if (sd_index < 0)
+    if (sd_index_raw < 0)
         return;
 
+    // TODO: Upgrade Disk::index and sd_index_raw to size_t, removing this cast.
+    const auto sd_index = static_cast<size_t>(sd_index_raw);
     if (sd_index >= Config.cacheSwap.n_configured)
         return;
 
@@ -234,9 +236,9 @@ storeRebuildProgress(int sd_index, int total, int sofar)
     if (squid_curtime - last_report < 15)
         return;
 
-    for (sd_index = 0; sd_index < Config.cacheSwap.n_configured; ++sd_index) {
-        n += (double) RebuildProgress[sd_index].scanned;
-        d += (double) RebuildProgress[sd_index].total;
+    for (size_t diskIndex = 0; diskIndex < Config.cacheSwap.n_configured; ++diskIndex) {
+        n += (double) RebuildProgress[diskIndex].scanned;
+        d += (double) RebuildProgress[diskIndex].total;
     }
 
     debugs(20, Important(57), "Indexing cache entries: " << Progress(n, d));
index 205dc59b8c052d468073dfce42a09673812aedf6..1b403f40217dd19702e75f871c29a4ca4dc16d8b 100644 (file)
@@ -111,7 +111,7 @@ addedEntry(Store::Disk *aStore,
     e->swap_filen = 0; /* garh - lower level*/
     e->swap_dirn = -1;
 
-    for (int i=0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         if (INDEXSD(i) == aStore)
             e->swap_dirn = i;
     }
index 232664e8c7aa2e89c024b8c18902c0076bdf2412..f429759b2c19258c535891544344c120470cb313 100644 (file)
@@ -89,7 +89,7 @@ addedEntry(Store::Disk *aStore,
     e->swap_filen = 0; /* garh - lower level*/
     e->swap_dirn = -1;
 
-    for (int i=0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         if (INDEXSD(i) == aStore)
             e->swap_dirn = i;
     }
index e96a95b077bc2474c9067810294c0545fa9ad57d..e33269f5cbef42e26463813c7a2f93134e42ea14 100644 (file)
@@ -180,7 +180,7 @@ bool
 unlinkdNeeded(void)
 {
     // we should start unlinkd if there are any cache_dirs using it
-    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+    for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
         const RefCount<SwapDir> sd = Config.cacheSwap.swapDirs[i];
         if (sd->unlinkdUseful())
             return true;