Skip to content

Commit

Permalink
Fix GCC v13 LTO build [-Walloc-size-larger-than=] (#1929)
Browse files Browse the repository at this point in the history
    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.
  • Loading branch information
juju4 authored and squid-anubis committed Feb 23, 2025
1 parent 28a2ea0 commit 91d1cfb
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 93 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ Thank you!
JPP <[email protected]>
Juan <[email protected]>
Juerg Michel
Juju4 <[email protected]>
Julien Pinon <[email protected]>
Karl Benoit <[email protected]>
Khalid Abdullah <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/DiskIO/DiskThreads/DiskThreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 5 additions & 7 deletions src/DiskIO/DiskThreads/aiops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -215,7 +215,6 @@ squidaio_xstrfree(char *str)
void
squidaio_init(void)
{
int i;
squidaio_thread_t *threadp;

if (squidaio_initialised)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -999,7 +998,6 @@ void
squidaio_stats(StoreEntry * sentry)
{
squidaio_thread_t *threadp;
int i;

if (!squidaio_initialised)
return;
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DiskIO/DiskThreads/async_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/SquidConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class DiskConfig {
~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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/auth/SchemeConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/auth/SchemeConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class SchemeConfig
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;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/basic/Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/auth/basic/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Config : public Auth::SchemeConfig
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;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/digest/Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/auth/digest/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Config : public Auth::SchemeConfig
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;

Expand Down
2 changes: 1 addition & 1 deletion src/fs/rock/RockSwapDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
12 changes: 6 additions & 6 deletions src/fs/ufs/UFSSwapDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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));

Expand Down Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/fs/ufs/UFSSwapDir.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class UFSSwapDir : public SwapDir

private:
void parseSizeL1L2();
static int NumberOfUFSDirs;
static size_t NumberOfUFSDirs;
static int * UFSDirToGlobalDirMapping;
bool pathIsDirectory(const char *path)const;
int swaplog_fd;
Expand Down
24 changes: 14 additions & 10 deletions src/pconn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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_];
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/pconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ class IdleConnList: public hash_link, private IndependentRunner

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;
Expand All @@ -81,9 +83,9 @@ class IdleConnList: public hash_link, private IndependentRunner
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
Expand Down
2 changes: 1 addition & 1 deletion src/store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 91d1cfb

Please sign in to comment.