From: Amos Jeffries Date: Mon, 11 Apr 2011 12:00:03 +0000 (-0600) Subject: ICC support: code polish to reduce compile warnings X-Git-Tag: SQUID_3_1_12_1~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca11626cbe9091abb9838bd2d4277f7b111e598e;p=thirdparty%2Fsquid.git ICC support: code polish to reduce compile warnings size_t is guaranteed to be >= 0 and other signed/unsigned comparison issues --- diff --git a/src/BodyPipe.cc b/src/BodyPipe.cc index aea639da48..417e1bbd4b 100644 --- a/src/BodyPipe.cc +++ b/src/BodyPipe.cc @@ -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 diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index b40b08de80..90480976bd 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -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; diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 1c1bb3da23..974abd08b2 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -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 diff --git a/src/HttpRequestMethod.h b/src/HttpRequestMethod.h index 03c91c7a2b..873aabcc24 100644 --- a/src/HttpRequestMethod.h +++ b/src/HttpRequestMethod.h @@ -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; diff --git a/src/String.cc b/src/String.cc index 40eae2c59e..0d886f42df 100644 --- a/src/String.cc +++ b/src/String.cc @@ -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); diff --git a/src/acl/DomainData.cc b/src/acl/DomainData.cc index 26950937fe..411bc44079 100644 --- a/src/acl/DomainData.cc +++ b/src/acl/DomainData.cc @@ -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(a); + const char *d = static_cast(b); return matchDomainName(h, d); } @@ -86,8 +86,8 @@ template 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(b); + char * const d2 = static_cast(a); int ret; ret = aclHostDomainCompare(d1, d2); diff --git a/src/adaptation/icap/ModXact.cc b/src/adaptation/icap/ModXact.cc index 2d5093e6c8..2e0fbc90e7 100644 --- a/src/adaptation/icap/ModXact.cc +++ b/src/adaptation/icap/ModXact.cc @@ -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(size) >= 0); theStart += static_cast(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; diff --git a/src/adaptation/icap/Xaction.cc b/src/adaptation/icap/Xaction.cc index 3925fdcb63..ba7d6a7dfa 100644 --- a/src/adaptation/icap/Xaction.cc +++ b/src/adaptation/icap/Xaction.cc @@ -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; diff --git a/src/client_side.cc b/src/client_side.cc index 4ac024501e..9e66a24fbe 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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."); diff --git a/src/client_side_request.cci b/src/client_side_request.cci index a9a043853e..ddbbc078ff 100644 --- a/src/client_side_request.cci +++ b/src/client_side_request.cci @@ -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_)) diff --git a/src/client_side_request.h b/src/client_side_request.h index e4f710a470..d92b4e0df6 100644 --- a/src/client_side_request.h +++ b/src/client_side_request.h @@ -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; diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 4bd88db07d..2b7efba865 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -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); } diff --git a/src/ftp.cc b/src/ftp.cc index d97b0df2db..a53c81652f 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -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; } diff --git a/src/helper.cc b/src/helper.cc index f9807b8076..31c89058de 100644 --- a/src/helper.cc +++ b/src/helper.cc @@ -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; } diff --git a/src/ip/IpAddress.cc b/src/ip/IpAddress.cc index d17eb1e22c..f13da467ad 100644 --- a/src/ip/IpAddress.cc +++ b/src/ip/IpAddress.cc @@ -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(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(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(13),blen)); assert(false); } diff --git a/src/store.cc b/src/store.cc index d1be5ee5f2..7d40515e35 100644 --- a/src/store.cc +++ b/src/store.cc @@ -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); diff --git a/src/tunnel.cc b/src/tunnel.cc index eacc435857..eb34ce568b 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -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; } diff --git a/src/urn.cc b/src/urn.cc index e96f2ad1df..5c513a6a97 100644 --- a/src/urn.cc +++ b/src/urn.cc @@ -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; } diff --git a/src/whois.cc b/src/whois.cc index d7297c4858..03076c9659 100644 --- a/src/whois.cc +++ b/src/whois.cc @@ -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 diff --git a/test-suite/debug.cc b/test-suite/debug.cc index 02f5b08a6b..19c7011d02 100644 --- a/test-suite/debug.cc +++ b/test-suite/debug.cc @@ -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;