]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
ICC support: code polish to reduce compile warnings
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 11 Apr 2011 12:00:03 +0000 (06:00 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 11 Apr 2011 12:00:03 +0000 (06:00 -0600)
size_t is guaranteed to be >= 0 and other signed/unsigned comparison issues

20 files changed:
src/BodyPipe.cc
src/HttpHeader.cc
src/HttpRequest.h
src/HttpRequestMethod.h
src/String.cc
src/acl/DomainData.cc
src/adaptation/icap/ModXact.cc
src/adaptation/icap/Xaction.cc
src/client_side.cc
src/client_side_request.cci
src/client_side_request.h
src/dns_internal.cc
src/ftp.cc
src/helper.cc
src/ip/IpAddress.cc
src/store.cc
src/tunnel.cc
src/urn.cc
src/whois.cc
test-suite/debug.cc

index aea639da48244cd4dd6837f19e5b4dcd8c1b74ae..417e1bbd4b19059af0c6253e37586857000b6850 100644 (file)
@@ -148,7 +148,6 @@ BodyPipe::~BodyPipe()
 void BodyPipe::setBodySize(uint64_t aBodySize)
 {
     assert(!bodySizeKnown());
-    assert(aBodySize >= 0);
     assert(thePutSize <= aBodySize);
 
     // If this assert fails, we need to add code to check for eof and inform
index b40b08de8068ee7f3b59c6adf45ccd434e900c5a..90480976bd1d9320d2879b2eeb8e979957101013 100644 (file)
@@ -1715,15 +1715,14 @@ httpHeaderStoreReport(StoreEntry * e)
 http_hdr_type
 httpHeaderIdByName(const char *name, size_t name_len, const HttpHeaderFieldInfo * info, int end)
 {
-    int i;
-
-    for (i = 0; i < end; ++i) {
-        if (name_len >= 0 && name_len != info[i].name.size())
-            continue;
+    if (name_len > 0) {
+        for (int i = 0; i < end; ++i) {
+            if (name_len != info[i].name.size())
+                continue;
 
-        if (!strncasecmp(name, info[i].name.termedBuf(),
-                         name_len < 0 ? info[i].name.size() + 1 : name_len))
-            return info[i].id;
+            if (!strncasecmp(name, info[i].name.termedBuf(), name_len))
+                return info[i].id;
+        }
     }
 
     return HDR_BAD_HDR;
index 1c1bb3da234be00bd19afaec5301accfb0c90f17..974abd08b25adf496df41ae6e1afaf06cf63834c 100644 (file)
@@ -104,7 +104,7 @@ public:
         }
     };
     inline const char* GetHost(void) const { return host; };
-    inline const int GetHostIsNumeric(void) const { return host_is_numeric; };
+    inline int GetHostIsNumeric(void) const { return host_is_numeric; };
 
 #if USE_ADAPTATION
     /// Returns possibly nil history, creating it if adapt. logging is enabled
index 03c91c7a2b694c2a44cf88c548ffb37f37c75ccb..873aabcc249924a67999e7c8232170ce0f22fc14 100644 (file)
@@ -137,10 +137,10 @@ public:
      \retval METHOD_OTHER  the method is not recognized and has no unique ID
      \retval *             the method is on of the recognized HTTP methods.
      */
-    _method_t const id() const { return theMethod; }
+    _method_t id() const { return theMethod; }
 
     /** Get a char string representation of the method. */
-    char const* image() const;
+    char const * image() const;
 
     bool isCacheble() const;
     bool purgesOthers() const;
index 40eae2c59e644b40278cdc9bbd4f15a8b1743ed5..0d886f42df47729abb82c7b71c1bfe38601cfbf4 100644 (file)
@@ -247,7 +247,8 @@ String::absorb(String &old)
 String
 String::substr(String::size_type from, String::size_type to) const
 {
-    Must(from >= 0 && from < size());
+//    Must(from >= 0 && from < size());
+    Must(from < size());
     Must(to > 0 && to <= size());
     Must(to > from);
 
index 26950937fe42865f39b513db3f7fdaeda0df4eb4..411bc440798893383158b1a5dbcfabb223f95905 100644 (file)
@@ -74,8 +74,8 @@ splaystrcmp (T&l, T&r)
 static int
 aclHostDomainCompare( char *const &a, char * const &b)
 {
-    const char *h = (const char *)a;
-    const char *d = (const char *)b;
+    const char *h = static_cast<const char *>(a);
+    const char *d = static_cast<const char *>(b);
     return matchDomainName(h, d);
 }
 
@@ -86,8 +86,8 @@ template<class T>
 int
 aclDomainCompare(T const &a, T const &b)
 {
-    char * const d1 = (char *const)b;
-    char * const d2 = (char *const )a;
+    char * const d1 = static_cast<char *>(b);
+    char * const d2 = static_cast<char *>(a);
     int ret;
     ret = aclHostDomainCompare(d1, d2);
 
index 2d5093e6c8571112e95a4afcf8dc2b7dd944202a..2e0fbc90e7000892aae820a18dfe0a2392f42d8f 100644 (file)
@@ -1374,8 +1374,6 @@ void Adaptation::Icap::ModXact::decideOnPreview()
 
     // we decided to do preview, now compute its size
 
-    Must(wantedSize >= 0);
-
     // cannot preview more than we can backup
     size_t ad = min(wantedSize, TheBackupLimit);
 
@@ -1622,7 +1620,7 @@ void Adaptation::Icap::VirginBodyAct::disable()
 void Adaptation::Icap::VirginBodyAct::progress(size_t size)
 {
     Must(active());
-    Must(size >= 0);
+    Must(static_cast<int64_t>(size) >= 0);
     theStart += static_cast<int64_t>(size);
 }
 
@@ -1639,7 +1637,6 @@ Adaptation::Icap::Preview::Preview(): theWritten(0), theAd(0), theState(stDisabl
 void Adaptation::Icap::Preview::enable(size_t anAd)
 {
     // TODO: check for anAd not exceeding preview size limit
-    Must(anAd >= 0);
     Must(!enabled());
     theAd = anAd;
     theState = stWriting;
index 3925fdcb6358ac631620517ec07489ee04be6eaa..ba7d6a7dfa53ab3909cf798d60796746ab3ef62a 100644 (file)
@@ -355,7 +355,6 @@ void Adaptation::Icap::Xaction::noteCommRead(const CommIoCbParams &io)
     reader = NULL;
 
     Must(io.flag == COMM_OK);
-    Must(io.size >= 0);
 
     if (!io.size) {
         commEof = true;
index 4ac024501e5e7a36c9f1e73be249f60f3ab90e2d..9e66a24fbebd64f876ad60ac4e4179a2f1bf10f8 100644 (file)
@@ -966,11 +966,6 @@ ClientSocketContext::packRange(StoreIOBuffer const &source, MemBuf * mb)
 
         }
 
-        /*
-         * paranoid check
-         */
-        assert((available.size() >= 0 && i->debt() >= 0) || i->debt() == -1);
-
         if (!canPackMoreRanges()) {
             debugs(33, 3, "clientPackRange: Returning because !canPackMoreRanges.");
 
index a9a043853efe3426bcd2cbe5784b59e9a7d8e5fb..ddbbc078ff666b926f8e4dface42aa997321d552 100644 (file)
@@ -50,15 +50,6 @@ ClientHttpRequest::memObject() const
 }
 
 ConnStateData *
-ClientHttpRequest::getConn()
-{
-    if (!cbdataReferenceValid(conn_))
-        return NULL;
-
-    return conn_;
-}
-
-ConnStateData * const
 ClientHttpRequest::getConn() const
 {
     if (!cbdataReferenceValid(conn_))
index e4f710a470e68d13a8d454c3ab39e58188606958..d92b4e0df6151ce0fa5b63bdfe0aefd597d3d749 100644 (file)
@@ -93,8 +93,7 @@ public:
     _SQUID_INLINE_ StoreEntry *loggingEntry() const;
     void loggingEntry(StoreEntry *);
 
-    _SQUID_INLINE_ ConnStateData * getConn();
-    _SQUID_INLINE_ ConnStateData * const getConn() const;
+    _SQUID_INLINE_ ConnStateData * getConn() const;
     _SQUID_INLINE_ void setConn(ConnStateData *);
     HttpRequest *request;              /* Parsed URL ... */
     char *uri;
index 4bd88db07d8257bc3df7aa6b75723fdb1e6d1b51..2b7efba865adb6baf00828f2c12b16db131c1fbd 100644 (file)
@@ -1574,13 +1574,11 @@ idnsALookup(const char *name, IDNSCB * callback, void *data)
            ", id = 0x" << std::hex << q->id);
 
     q->callback = callback;
-
     q->callback_data = cbdataReference(data);
 
     q->start_t = current_time;
 
     idnsCacheQuery(q);
-
     idnsSendQuery(q);
 }
 
@@ -1626,13 +1624,11 @@ idnsPTRLookup(const IpAddress &addr, IDNSCB * callback, void *data)
            ", id = 0x" << std::hex << q->id);
 
     q->callback = callback;
-
     q->callback_data = cbdataReference(data);
 
     q->start_t = current_time;
 
     idnsCacheQuery(q);
-
     idnsSendQuery(q);
 }
 
index d97b0df2dbefb1c44e3986fc8ee54e464c80ac4e..a53c81652f68f1f3aefb0bfeb02f391974f1629c 100644 (file)
@@ -1362,7 +1362,7 @@ FtpStateData::dataRead(const CommIoCbParams &io)
         IOStats.Ftp.read_hist[bin]++;
     }
 
-    if (io.flag != COMM_OK || io.size < 0) {
+    if (io.flag != COMM_OK) {
         debugs(50, ignoreErrno(io.xerrno) ? 3 : DBG_IMPORTANT,
                "ftpDataRead: read error: " << xstrerr(io.xerrno));
 
@@ -1859,7 +1859,7 @@ void FtpStateData::ftpReadControlReply(const CommIoCbParams &io)
         fd_bytes(io.fd, io.size, FD_READ);
     }
 
-    if (io.flag != COMM_OK || io.size < 0) {
+    if (io.flag != COMM_OK) {
         debugs(50, ignoreErrno(io.xerrno) ? 3 : DBG_IMPORTANT,
                "ftpReadControlReply: read error: " << xstrerr(io.xerrno));
 
@@ -1868,9 +1868,7 @@ void FtpStateData::ftpReadControlReply(const CommIoCbParams &io)
         } else {
             failed(ERR_READ_ERROR, io.xerrno);
             /* failed closes ctrl.fd and frees ftpState */
-            return;
         }
-
         return;
     }
 
index f9807b8076c50ca187dfd6198f503f942d88a824..31c89058de94dbf7bd2768ccb18a08b902ec4ffa 100644 (file)
@@ -857,12 +857,8 @@ helperHandleRead(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, voi
 
     debugs(84, 5, "helperHandleRead: " << len << " bytes from " << hlp->id_name << " #" << srv->index + 1);
 
-    if (flag != COMM_OK || len <= 0) {
-        if (len < 0)
-            debugs(84, 1, "helperHandleRead: FD " << fd << " read: " << xstrerror());
-
+    if (flag != COMM_OK || len == 0) {
         comm_close(fd);
-
         return;
     }
 
@@ -971,12 +967,8 @@ helperStatefulHandleRead(int fd, char *buf, size_t len, comm_err_t flag, int xer
            hlp->id_name << " #" << srv->index + 1);
 
 
-    if (flag != COMM_OK || len <= 0) {
-        if (len < 0)
-            debugs(84, 1, "helperStatefulHandleRead: FD " << fd << " read: " << xstrerror());
-
+    if (flag != COMM_OK || len == 0) {
         comm_close(fd);
-
         return;
     }
 
index d17eb1e22c833d4604bb745cb26c66ac0575c421..f13da467ad4e292aec7bbbf3de549c62910f5703 100644 (file)
@@ -773,7 +773,7 @@ char* IpAddress::NtoA(char* buf, const unsigned int blen, int force) const
     /* some external code may have blindly memset a parent. */
     /* thats okay, our default is known */
     if ( IsAnyAddr() ) {
-        memcpy(buf,"::\0", min((const unsigned int)3,blen));
+        memcpy(buf,"::\0", min(static_cast<unsigned int>(3),blen));
         return buf;
     }
 
@@ -783,7 +783,7 @@ char* IpAddress::NtoA(char* buf, const unsigned int blen, int force) const
     /* However IPv4 CAN. */
     if ( force == AF_INET && !IsIPv4() ) {
         if ( IsIPv6() ) {
-            memcpy(buf, "{!IPv4}\0", min((const unsigned int)8,blen));
+            memcpy(buf, "{!IPv4}\0", min(static_cast<unsigned int>(8),blen));
         }
         return buf;
     }
@@ -802,7 +802,7 @@ char* IpAddress::NtoA(char* buf, const unsigned int blen, int force) const
                force << "). accepted={" << AF_UNSPEC << "," << AF_INET << "," << AF_INET6 << "}");
         fprintf(stderr,"WARNING: Corrupt IP Address details OR required to display in unknown format (%d). accepted={%d,%d,%d} ",
                 force, AF_UNSPEC, AF_INET, AF_INET6);
-        memcpy(buf,"dead:beef::\0", min((const unsigned int)13,blen));
+        memcpy(buf,"dead:beef::\0", min(static_cast<unsigned int>(13),blen));
         assert(false);
     }
 
index d1be5ee5f2677c274f77336f48f85b8702c024a0..7d40515e357ea81492ee51c2b2d7b337ae3850ee 100644 (file)
@@ -804,7 +804,6 @@ void
 StoreEntry::write (StoreIOBuffer writeBuffer)
 {
     assert(mem_obj != NULL);
-    assert(writeBuffer.length >= 0);
     /* This assert will change when we teach the store to update */
     PROF_start(StoreEntry_write);
     assert(store_status == STORE_PENDING);
index eacc43585702516fdc00c41cfa62a3c0092294c0..eb34ce568b5202ba04e6f18fe992792ccd266ef5 100644 (file)
@@ -312,7 +312,7 @@ TunnelStateData::copy (size_t len, comm_err_t errcode, int xerrno, Connection &f
     if (!fd_closed(server.fd()))
         commSetTimeout(server.fd(), Config.Timeout.read, tunnelTimeout, this);
 
-    if (len < 0 || errcode)
+    if (errcode)
         from.error (xerrno);
     else if (len == 0 || fd_closed(to.fd())) {
         comm_close(from.fd());
@@ -343,12 +343,10 @@ TunnelStateData::writeServerDone(char *buf, size_t len, comm_err_t flag, int xer
 {
     debugs(26, 3, "tunnelWriteServer: FD " << server.fd() << ", " << len << " bytes written");
 
-    if (flag == COMM_ERR_CLOSING)
-        return;
-
     /* Error? */
-    if (len < 0 || flag != COMM_OK) {
-        server.error(xerrno); // may call comm_close
+    if (flag != COMM_OK) {
+        if (flag != COMM_ERR_CLOSING)
+            server.error(xerrno); // may call comm_close
         return;
     }
 
@@ -404,12 +402,10 @@ TunnelStateData::writeClientDone(char *buf, size_t len, comm_err_t flag, int xer
 {
     debugs(26, 3, "tunnelWriteClient: FD " << client.fd() << ", " << len << " bytes written");
 
-    if (flag == COMM_ERR_CLOSING)
-        return;
-
     /* Error? */
-    if (len < 0 || flag != COMM_OK) {
-        client.error(xerrno); // may call comm_close
+    if (flag != COMM_OK) {
+        if (flag != COMM_ERR_CLOSING)
+            client.error(xerrno); // may call comm_close
         return;
     }
 
index e96f2ad1df998e37d5375463833f9c4300f5ed79..5c513a6a9780cd2ff76894e68d48eef2cd4b245e 100644 (file)
@@ -327,9 +327,9 @@ urnHandleReply(void *data, StoreIOBuffer result)
     char *buf = urnState->reqbuf;
     StoreIOBuffer tempBuffer;
 
-    debugs(52, 3, "urnHandleReply: Called with size=" << (unsigned int)result.length << ".");
+    debugs(52, 3, "urnHandleReply: Called with size=" << result.length << ".");
 
-    if (EBIT_TEST(urlres_e->flags, ENTRY_ABORTED) || result.length == 0 || result.flags.error < 0) {
+    if (EBIT_TEST(urlres_e->flags, ENTRY_ABORTED) || result.length == 0 || result.flags.error) {
         urnHandleReplyError(urnState, urlres_e);
         return;
     }
index d7297c485817eb5df341cf99ca239fac8fa1616b..03076c9659ce5bce4cf990845f3aa9db91f31f2d 100644 (file)
@@ -135,65 +135,55 @@ WhoisState::setReplyToOK(StoreEntry *sentry)
 void
 WhoisState::readReply (int fd, char *aBuffer, size_t aBufferLength, comm_err_t flag, int xerrno)
 {
-    int do_next_read = 0;
-
     /* Bail out early on COMM_ERR_CLOSING - close handlers will tidy up for us */
-
-    if (flag == COMM_ERR_CLOSING) {
+    if (flag == COMM_ERR_CLOSING)
         return;
-    }
 
     aBuffer[aBufferLength] = '\0';
     debugs(75, 3, "whoisReadReply: FD " << fd << " read " << aBufferLength << " bytes");
     debugs(75, 5, "{" << aBuffer << "}");
 
-    if (flag == COMM_OK && aBufferLength > 0) {
-        if (!dataWritten)
-            setReplyToOK(entry);
-
-        kb_incr(&statCounter.server.all.kbytes_in, aBufferLength);
-
-        kb_incr(&statCounter.server.http.kbytes_in, aBufferLength);
-
-        /* No range support, we always grab it all */
-        dataWritten = true;
-
-        entry->append(aBuffer, aBufferLength);
-
-        entry->flush();
-
-        do_next_read = 1;
-    } else if (flag != COMM_OK || aBufferLength < 0) {
+    if (flag != COMM_OK) {
         debugs(50, 2, "whoisReadReply: FD " << fd << ": read failure: " << xstrerror() << ".");
 
         if (ignoreErrno(errno)) {
-            do_next_read = 1;
+            comm_read(fd, aBuffer, BUFSIZ, whoisReadReply, this);
         } else {
             ErrorState *err;
             err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR, fwd->request);
             err->xerrno = errno;
             fwd->fail(err);
             comm_close(fd);
-            do_next_read = 0;
         }
-    } else {
-        entry->timestampsSet();
-        entry->flush();
-
-        if (!EBIT_TEST(entry->flags, RELEASE_REQUEST))
-            entry->setPublicKey();
+        return;
+    }
 
-        fwd->complete();
+    if (aBufferLength > 0) {
+        if (!dataWritten)
+            setReplyToOK(entry);
 
-        debugs(75, 3, "whoisReadReply: Done: " << entry->url()  );
+        kb_incr(&statCounter.server.all.kbytes_in, aBufferLength);
+        kb_incr(&statCounter.server.http.kbytes_in, aBufferLength);
 
-        comm_close(fd);
+        /* No range support, we always grab it all */
+        dataWritten = true;
+        entry->append(aBuffer, aBufferLength);
+        entry->flush();
 
-        do_next_read = 0;
+        comm_read(fd, aBuffer, BUFSIZ, whoisReadReply, this);
+        return;
     }
 
-    if (do_next_read)
-        comm_read(fd, aBuffer, BUFSIZ, whoisReadReply, this);
+    /* no bytes read. stop reading */
+    entry->timestampsSet();
+    entry->flush();
+
+    if (!EBIT_TEST(entry->flags, RELEASE_REQUEST))
+        entry->setPublicKey();
+
+    fwd->complete();
+    debugs(75, 3, "whoisReadReply: Done: " << entry->url());
+    comm_close(fd);
 }
 
 static void
index 02f5b08a6b1f68c9fab94c8c018cca5048472d0a..19c7011d02c7e704c9393f3da2938ea826cb93e9 100644 (file)
@@ -42,7 +42,7 @@ class StreamTest
 {
 public:
     std::ostream &serialise(std::ostream &);
-    int const getAnInt() const;
+    int getAnInt() const;
     char const *getACString() const;
 };
 
@@ -58,7 +58,7 @@ StreamTest::serialise(std::ostream &aStream)
     return aStream;
 }
 
-int const
+int
 StreamTest::getAnInt() const
 {
     return 5;