From: Amos Jeffries Date: Fri, 2 Jan 2015 04:13:30 +0000 (-0800) Subject: Fix several uninitilized member issues X-Git-Tag: merge-candidate-3-v1~393 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2673511605f44d53d41073b6e049f682a76ed24d;p=thirdparty%2Fsquid.git Fix several uninitilized member issues * Digest auth header field-value parser * HTTP header statistics state data * logformat parser token data --- diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index b8d21ca77f..af09e78e12 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -23,11 +23,22 @@ #include /* a row in the table used for parsing cache control header and statistics */ -typedef struct { +class HttpHeaderCcFields +{ +public: + HttpHeaderCcFields() : name(NULL), id(CC_BADHDR), stat() {} + HttpHeaderCcFields(const char *aName, http_hdr_cc_type aTypeId) : name(aName), id(aTypeId) {} + // nothing to do as name is a pointer to global static string + ~HttpHeaderCcFields() {} + const char *name; http_hdr_cc_type id; HttpHeaderFieldStat stat; -} HttpHeaderCcFields; + +private: + HttpHeaderCcFields(const HttpHeaderCcFields &); // not implemented + HttpHeaderCcFields &operator =(const HttpHeaderCcFields &); // not implemented +}; /* order must match that of enum http_hdr_cc_type. The constraint is verified at initialization time */ static HttpHeaderCcFields CcAttrs[CC_ENUM_END] = { diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 7913511518..59dad66fc8 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -322,13 +322,18 @@ static http_hdr_type HopByHopHeadersArr[] = { }; /* header accounting */ +// NP: keep in sync with enum http_hdr_owner_type static HttpHeaderStat HttpHeaderStats[] = { - {"all"}, + {/*hoNone*/ "all", NULL}, #if USE_HTCP - {"HTCP reply"}, + {/*hoHtcpReply*/ "HTCP reply", &ReplyHeadersMask}, #endif - {"request"}, - {"reply"} + {/*hoRequest*/ "request", &RequestHeadersMask}, + {/*hoReply*/ "reply", &ReplyHeadersMask} +#if USE_OPENSSL + /* hoErrorDetail */ +#endif + /* hoEnd */ }; static int HttpHeaderStatCount = countof(HttpHeaderStats); @@ -343,7 +348,6 @@ class StoreEntry; static void httpHeaderNoteParsedEntry(http_hdr_type id, String const &value, int error); -static void httpHeaderStatInit(HttpHeaderStat * hs, const char *label); static void httpHeaderStatDump(const HttpHeaderStat * hs, StoreEntry * e); /** store report about current header usage and other stats */ @@ -364,7 +368,6 @@ httpHeaderRegisterWithCacheManager(void) void httpHeaderInitModule(void) { - int i; /* check that we have enough space for masks */ assert(8 * sizeof(HttpHeaderMask) >= HDR_ENUM_END); /* all headers must be described */ @@ -390,18 +393,8 @@ httpHeaderInitModule(void) httpHeaderMaskInit(&HopByHopHeadersMask, 0); httpHeaderCalcMask(&HopByHopHeadersMask, HopByHopHeadersArr, countof(HopByHopHeadersArr)); - /* init header stats */ + /* header stats initialized by class constructor */ assert(HttpHeaderStatCount == hoReply + 1); - for (i = 0; i < HttpHeaderStatCount; ++i) - httpHeaderStatInit(HttpHeaderStats + i, HttpHeaderStats[i].label); - - HttpHeaderStats[hoRequest].owner_mask = &RequestHeadersMask; - - HttpHeaderStats[hoReply].owner_mask = &ReplyHeadersMask; - -#if USE_HTCP - HttpHeaderStats[hoHtcpReply].owner_mask = &ReplyHeadersMask; -#endif /* init dependent modules */ httpHdrCcInitModule(); @@ -419,19 +412,6 @@ httpHeaderCleanModule(void) httpHdrScCleanModule(); } -static void -httpHeaderStatInit(HttpHeaderStat * hs, const char *label) -{ - assert(hs); - assert(label); - memset(hs, 0, sizeof(HttpHeaderStat)); - hs->label = label; - hs->hdrUCountDistr.enumInit(32); /* not a real enum */ - hs->fieldTypeDistr.enumInit(HDR_ENUM_END); - hs->ccTypeDistr.enumInit(CC_ENUM_END); - hs->scTypeDistr.enumInit(SC_ENUM_END); -} - /* * HttpHeader Implementation */ diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 9e0e0a1610..487bd688e5 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -55,10 +55,18 @@ typedef enum { hoEnd } http_hdr_owner_type; -// currently a POD class HttpHeaderFieldAttrs { public: + HttpHeaderFieldAttrs() : name(NULL), id(HDR_BAD_HDR), type(ftInvalid) {} + HttpHeaderFieldAttrs(const char *aName, http_hdr_type anId, field_type aType = ftInvalid) : name(aName), id(anId), type(aType) {} +#if __cplusplus >= 201103L + HttpHeaderFieldAttrs(const HttpHeaderFieldAttrs &) = default; + HttpHeaderFieldAttrs(HttpHeaderFieldAttrs &&) = default; +#endif + // nothing to do as name is a pointer to global const string + ~HttpHeaderFieldAttrs() {} + const char *name; http_hdr_type id; field_type type; diff --git a/src/HttpHeaderStat.h b/src/HttpHeaderStat.h index e441efd498..c01e26c11c 100644 --- a/src/HttpHeaderStat.h +++ b/src/HttpHeaderStat.h @@ -11,10 +11,45 @@ #include "StatHist.h" -/// per header statistics +/// HTTP per header statistics class HttpHeaderStat { public: + HttpHeaderStat() : + label(NULL), + owner_mask(NULL), + parsedCount(0), + ccParsedCount(0), + scParsedCount(0), + destroyedCount(0), + busyDestroyedCount(0) + { + hdrUCountDistr.enumInit(32); /* not a real enum */ + fieldTypeDistr.enumInit(HDR_ENUM_END); + ccTypeDistr.enumInit(CC_ENUM_END); + scTypeDistr.enumInit(SC_ENUM_END); + } + + HttpHeaderStat(const char *aLabel, HttpHeaderMask *aMask) : + label(aLabel), + owner_mask(aMask), + parsedCount(0), + ccParsedCount(0), + scParsedCount(0), + destroyedCount(0), + busyDestroyedCount(0) + { + assert(label); + hdrUCountDistr.enumInit(32); /* not a real enum */ + fieldTypeDistr.enumInit(HDR_ENUM_END); + ccTypeDistr.enumInit(CC_ENUM_END); + scTypeDistr.enumInit(SC_ENUM_END); + } + + // nothing to destruct as label is a pointer to global const string + // and owner_mask is a pointer to global static array + ~HttpHeaderStat() {} + const char *label; HttpHeaderMask *owner_mask; diff --git a/src/format/TokenTableEntry.h b/src/format/TokenTableEntry.h index c30da86b6d..3e88e3f072 100644 --- a/src/format/TokenTableEntry.h +++ b/src/format/TokenTableEntry.h @@ -30,6 +30,11 @@ namespace Format class TokenTableEntry { public: + TokenTableEntry() : configTag(NULL), tokenType(LFT_NONE), options(0) {} + TokenTableEntry(const char *aTag, const ByteCode_t &aType) : configTag(aTag), tokenType(aType), options(0) {} + // nothing to destruct configTag is pointer to global const string + ~TokenTableEntry() {} + /// the config file ASCII representation for this token /// just the base tag bytes, excluding any option syntax bytes const char *configTag; @@ -39,6 +44,10 @@ public: /// 32-bit mask? of options affecting the output display of this token uint32_t options; + +private: + TokenTableEntry(const TokenTableEntry&); // not implemented + TokenTableEntry &operator =(const TokenTableEntry&); // not implemented }; } // namespace Format