signed vs unsigned size_t ickiness in squid3 (fwd)

From: Henrik Nordstrom <hno@dont-contact.us>
Date: Tue, 3 Aug 2004 20:08:46 +0200 (CEST)

Please direct comments regarding the Squid source code to
squid-dev@squid-cache.org.

Posting is allowed for all as long as relevant to the Squid source.

Regards
Henrik

---------- Forwarded message ----------
Date: Tue, 3 Aug 2004 00:20:22 -0700
From: mohan <mki@mozone.net>
To: hno@squid-cache.org
Subject: signed vs unsigned size_t ickiness in squid3

Hi Henrik,

Just was trying out squid3 and noticed a problem with quickAbort
settings. Basically, with g++-3.x the meaning of size_t (also
per iso c++ spec from what I understand) is really an unsigned int.

In c, using gcc this is not the case, and size_t is infact a
signed int. With squid3, the first place you encounter this ickiness
directly, is in cache_cf.cc where the config is being parsed
with parse_kb_t. While most values are positive, there's that
quickAbortMin == -1 KB setting (per documentation and legacy squid2
carryover), which makes the config parser throw up all over the place.

Then, there are things such as:

store_client.cc:764

    size_t curlen = (size_t) mem->endOffset ();

    size_t minlen = (size_t) Config.quickAbort.min << 10;

    if (minlen < 0) {
        debug(90, 3) ("CheckQuickAbort2: NO disabled\n");
        return 0;
    }

Well, in the case of g++ 3, minlen will never be negative!

I shudder to think where else this assumption is made in the
rest of the code... I suppose one way to address this issue
might be to make a new namespace for squid that redefines all
the necessary types. But then again, it is probably going
to be better to fix all the broken assumptions across squid3.

FYI, this appears to be a duplicate of bug #905 which hasn't
been commented on since it's creation in January.

-mohan
Received on Tue Aug 03 2004 - 12:08:49 MDT

This archive was generated by hypermail pre-2.1.9 : Wed Sep 01 2004 - 12:00:04 MDT