From: Amos Jeffries Date: Thu, 19 Mar 2009 14:44:22 +0000 (+1300) Subject: Various errors detected by Coverity scan X-Git-Tag: SQUID_3_2_0_1~1112 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=89982fc0f740ebcfa248d8ae5fbd22eccaf33ac9;p=thirdparty%2Fsquid.git Various errors detected by Coverity scan --- diff --git a/lib/rfc2617.c b/lib/rfc2617.c index f5c50d4004..324d48078e 100644 --- a/lib/rfc2617.c +++ b/lib/rfc2617.c @@ -94,6 +94,11 @@ CvtBin(const HASHHEX Hex, HASH Bin) else Bin[i / 2] |= n; } +/* FIXME: Coverity detects the below as dead code. + Why? :: right here i == 32 + which means the first step of the for loop makes i==16 + and cannot be < HASHLEN (which is also 16) +*/ for (i = i / 2; i < HASHLEN; i++) { Bin[i] = '\0'; } diff --git a/src/auth/basic/auth_basic.cc b/src/auth/basic/auth_basic.cc index 4fdee3b525..9aa07bb53a 100644 --- a/src/auth/basic/auth_basic.cc +++ b/src/auth/basic/auth_basic.cc @@ -143,9 +143,8 @@ int AuthBasicUserRequest::authenticated() const { BasicUser const *basic_auth = dynamic_cast(user()); - assert (basic_auth != NULL); - if (basic_auth->authenticated()) + if (basic_auth && basic_auth->authenticated()) return 1; return 0; diff --git a/src/htcp.cc b/src/htcp.cc index ee54e9fae8..d0125207df 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -881,19 +881,20 @@ htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, IpAddr stuff.S.uri = spec->uri; stuff.S.version = spec->version; stuff.S.req_hdrs = spec->req_hdrs; - hdr.putInt(HDR_AGE, - e->timestamp <= squid_curtime ? - squid_curtime - e->timestamp : 0); + if(e) + hdr.putInt(HDR_AGE, (e->timestamp <= squid_curtime ? (squid_curtime - e->timestamp) : 0) ); + else + hdr.putInt(HDR_AGE, 0); hdr.packInto(&p); stuff.D.resp_hdrs = xstrdup(mb.buf); debugs(31, 3, "htcpTstReply: resp_hdrs = {" << stuff.D.resp_hdrs << "}"); mb.reset(); hdr.reset(); - if (e->expires > -1) + if (e && e->expires > -1) hdr.putTime(HDR_EXPIRES, e->expires); - if (e->lastmod > -1) + if (e && e->lastmod > -1) hdr.putTime(HDR_LAST_MODIFIED, e->lastmod); hdr.packInto(&p); diff --git a/src/ip/IpAddress.cc b/src/ip/IpAddress.cc index 2cf158280f..1fc77b1f55 100644 --- a/src/ip/IpAddress.cc +++ b/src/ip/IpAddress.cc @@ -651,10 +651,8 @@ IpAddress::IpAddress(IpAddress *s) IpAddress& IpAddress::operator =(IpAddress *s) { - IpAddress *tmp = NULL; if (!s) return *this; - tmp = dynamic_cast(s); - if (!tmp) return *this; + IpAddress *tmp = static_cast(s); return operator=(*tmp); }