------------------------------------------------------------ revno: 13734 revision-id: squid3@treenet.co.nz-20150120100307-wa5lckdl2w4kyd5r parent: squid3@treenet.co.nz-20150120094840-g5m6w5rn1vkfiana committer: Amos Jeffries branch nick: 3.5 timestamp: Tue 2015-01-20 02:03:07 -0800 message: HTCP: fix memory initialization errors memset() used to initialize HTCP objects made sense when they were structs. But now they are classes proper constructors need to be used to avoid memset() erasing vtable and other important areas. It also helps to reduce code and improve performance during init a tiny bit. memset() errors found by Clang 3.5 ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20150120100307-wa5lckdl2w4kyd5r # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # testament_sha1: 2554cee85132b8b686f9e95cc0174ca7db9eda94 # timestamp: 2015-01-20 10:47:00 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # base_revision_id: squid3@treenet.co.nz-20150120094840-\ # g5m6w5rn1vkfiana # # Begin patch === modified file 'src/htcp.cc' --- src/htcp.cc 2015-01-13 09:13:49 +0000 +++ src/htcp.cc 2015-01-20 10:03:07 +0000 @@ -47,8 +47,6 @@ typedef struct _htcpAuthHeader htcpAuthHeader; -typedef struct _htcpStuff htcpStuff; - typedef struct _htcpDetail htcpDetail; struct _Countstr { @@ -139,6 +137,17 @@ public: MEMPROXY_CLASS(htcpSpecifier); + htcpSpecifier() : + method(NULL), + uri(NULL), + version(NULL), + req_hdrs(NULL), + request(NULL), + checkHitRequest(NULL), + dhdr(NULL) + {} + // XXX: destructor? + void created (StoreEntry *newEntry); void checkHit(); void checkedHit(StoreEntry *e); @@ -166,7 +175,20 @@ char *cache_hdrs; }; -struct _htcpStuff { +class htcpStuff +{ +public: + htcpStuff(uint32_t id, int o, int r, int f) : + op(o), + rr(r), + f1(f), + response(0), + reason(0), + msg_id(id) + { + memset(&D, 0, sizeof(D)); + } + int op; int rr; int f1; @@ -834,19 +856,15 @@ static void htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, Ip::Address &from) { - htcpStuff stuff; static char pkt[8192]; HttpHeader hdr(hoHtcpReply); MemBuf mb; Packer p; ssize_t pktlen; - memset(&stuff, '\0', sizeof(stuff)); - stuff.op = HTCP_TST; - stuff.rr = RR_RESPONSE; - stuff.f1 = 0; + + htcpStuff stuff(dhdr->msg_id, HTCP_TST, RR_RESPONSE, 0); stuff.response = e ? 0 : 1; debugs(31, 3, "htcpTstReply: response = " << stuff.response); - stuff.msg_id = dhdr->msg_id; if (spec) { mb.init(); @@ -923,7 +941,6 @@ htcpClrReply(htcpDataHeader * dhdr, int purgeSucceeded, Ip::Address &from) { - htcpStuff stuff; static char pkt[8192]; ssize_t pktlen; @@ -932,20 +949,12 @@ if (dhdr->F1 == 0) return; - memset(&stuff, '\0', sizeof(stuff)); - - stuff.op = HTCP_CLR; - - stuff.rr = RR_RESPONSE; - - stuff.f1 = 0; + htcpStuff stuff(dhdr->msg_id, HTCP_CLR, RR_RESPONSE, 0); stuff.response = purgeSucceeded ? 0 : 2; debugs(31, 3, "htcpClrReply: response = " << stuff.response); - stuff.msg_id = dhdr->msg_id; - pktlen = htcpBuildPacket(pkt, sizeof(pkt), &stuff); if (pktlen == 0) { @@ -1538,7 +1547,6 @@ static char pkt[8192]; ssize_t pktlen; char vbuf[32]; - htcpStuff stuff; HttpHeader hdr(hoRequest); Packer pa; MemBuf mb; @@ -1551,11 +1559,8 @@ memset(&flags, '\0', sizeof(flags)); snprintf(vbuf, sizeof(vbuf), "%d/%d", req->http_ver.major, req->http_ver.minor); - stuff.op = HTCP_TST; - stuff.rr = RR_REQUEST; - stuff.f1 = 1; - stuff.response = 0; - stuff.msg_id = ++msg_id_counter; + + htcpStuff stuff(++msg_id_counter, HTCP_TST, RR_REQUEST, 1); SBuf sb = req->method.image(); stuff.S.method = sb.c_str(); stuff.S.uri = (char *) e->url(); @@ -1594,7 +1599,6 @@ static char pkt[8192]; ssize_t pktlen; char vbuf[32]; - htcpStuff stuff; HttpHeader hdr(hoRequest); Packer pa; MemBuf mb; @@ -1607,19 +1611,11 @@ memset(&flags, '\0', sizeof(flags)); snprintf(vbuf, sizeof(vbuf), "%d/%d", req->http_ver.major, req->http_ver.minor); - stuff.op = HTCP_CLR; - stuff.rr = RR_REQUEST; - stuff.f1 = 0; - stuff.response = 0; - stuff.msg_id = ++msg_id_counter; - switch (reason) { - case HTCP_CLR_INVALIDATION: + + htcpStuff stuff(++msg_id_counter, HTCP_CLR, RR_REQUEST, 0); + if (reason == HTCP_CLR_INVALIDATION) stuff.reason = 1; - break; - default: - stuff.reason = 0; - break; - } + SBuf sb = req->method.image(); stuff.S.method = sb.c_str(); if (e == NULL || e->mem_obj == NULL) {