From f56026633bdc79c0d5ad0f0c5eaa63c07eab5b94 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sat, 4 Mar 2017 00:36:02 +1300 Subject: [PATCH] Bug 4671 pt2: various GCC 7 compile errors --- src/DiskIO/DiskThreads/aiops.cc | 2 +- src/fde.cc | 6 +++--- src/fs/ufs/RebuildState.cc | 4 ++-- src/fs/ufs/RebuildState.h | 2 +- src/gopher.cc | 34 +++++++++++++-------------------- 5 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/DiskIO/DiskThreads/aiops.cc b/src/DiskIO/DiskThreads/aiops.cc index 9ab23b17a0..c6871a9cab 100644 --- a/src/DiskIO/DiskThreads/aiops.cc +++ b/src/DiskIO/DiskThreads/aiops.cc @@ -296,7 +296,7 @@ squidaio_init(void) /* Create threads and get them to sit in their wait loop */ squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t)); - assert(NUMTHREADS); + assert(NUMTHREADS != 0); for (i = 0; i < NUMTHREADS; ++i) { threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc(); diff --git a/src/fde.cc b/src/fde.cc index b48bb63869..1c1f831ab3 100644 --- a/src/fde.cc +++ b/src/fde.cc @@ -83,14 +83,14 @@ fde::DumpStats(StoreEntry *dumpEntry) char const * fde::remoteAddr() const { - static char buf[MAX_IPSTRLEN]; + static char buf[MAX_IPSTRLEN+7]; // 7 = length of ':port' strings *buf = 0; if (type == FD_SOCKET) { if (*ipaddr) - snprintf(buf, MAX_IPSTRLEN, "%s:%u", ipaddr, remote_port); + snprintf(buf, sizeof(buf), "%s:%u", ipaddr, remote_port); else - local_addr.toUrl(buf,MAX_IPSTRLEN); // toHostStr does not include port. + local_addr.toUrl(buf, sizeof(buf)); // toHostStr does not include port. } return buf; diff --git a/src/fs/ufs/RebuildState.cc b/src/fs/ufs/RebuildState.cc index 10ca3de504..17d7d23f50 100644 --- a/src/fs/ufs/RebuildState.cc +++ b/src/fs/ufs/RebuildState.cc @@ -463,7 +463,7 @@ Fs::Ufs::RebuildState::getNextFile(sfileno * filn_p, int *) } if (0 == in_dir) { /* we need to read in a new directory */ - snprintf(fullpath, MAXPATHLEN, "%s/%02X/%02X", + snprintf(fullpath, sizeof(fullpath), "%s/%02X/%02X", sd->path, curlvl1, curlvl2); @@ -509,7 +509,7 @@ Fs::Ufs::RebuildState::getNextFile(sfileno * filn_p, int *) continue; } - snprintf(fullfilename, MAXPATHLEN, "%s/%s", + snprintf(fullfilename, sizeof(fullfilename), "%s/%s", fullpath, entry->d_name); debugs(47, 3, HERE << "Opening " << fullfilename); fd = file_open(fullfilename, O_RDONLY | O_BINARY); diff --git a/src/fs/ufs/RebuildState.h b/src/fs/ufs/RebuildState.h index e819fee06c..98a0467f60 100644 --- a/src/fs/ufs/RebuildState.h +++ b/src/fs/ufs/RebuildState.h @@ -55,7 +55,7 @@ public: dirent_t *entry; DIR *td; char fullpath[MAXPATHLEN]; - char fullfilename[MAXPATHLEN]; + char fullfilename[MAXPATHLEN*2]; StoreRebuildData counts; diff --git a/src/gopher.cc b/src/gopher.cc index fee738228c..1eaed121dd 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -826,7 +826,7 @@ gopherReadReply(const Comm::ConnectionPointer &conn, char *buf, size_t len, Comm * This will be called when request write is complete. Schedule read of reply. */ static void -gopherSendComplete(const Comm::ConnectionPointer &conn, char *buf, size_t size, Comm::Flag errflag, int xerrno, void *data) +gopherSendComplete(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag errflag, int xerrno, void *data) { GopherStateData *gopherState = (GopherStateData *) data; StoreEntry *entry = gopherState->entry; @@ -846,10 +846,6 @@ gopherSendComplete(const Comm::ConnectionPointer &conn, char *buf, size_t size, err->url = xstrdup(entry->url()); gopherState->fwd->fail(err); gopherState->serverConn->close(); - - if (buf) - memFree(buf, MEM_4K_BUF); /* Allocated by gopherSendRequest. */ - return; } @@ -891,9 +887,6 @@ gopherSendComplete(const Comm::ConnectionPointer &conn, char *buf, size_t size, AsyncCall::Pointer call = commCbCall(5,5, "gopherReadReply", CommIoCbPtrFun(gopherReadReply, gopherState)); entry->delayAwareRead(conn, gopherState->replybuf, BUFSIZ, call); - - if (buf) - memFree(buf, MEM_4K_BUF); /* Allocated by gopherSendRequest. */ } /** @@ -903,32 +896,31 @@ static void gopherSendRequest(int, void *data) { GopherStateData *gopherState = (GopherStateData *)data; - char *buf = (char *)memAllocate(MEM_4K_BUF); + MemBuf mb; + mb.init(); if (gopherState->type_id == GOPHER_CSO) { const char *t = strchr(gopherState->request, '?'); - if (t != NULL) + if (t) ++t; /* skip the ? */ else t = ""; - snprintf(buf, 4096, "query %s\r\nquit\r\n", t); - } else if (gopherState->type_id == GOPHER_INDEX) { - char *t = strchr(gopherState->request, '?'); - - if (t != NULL) - *t = '\t'; - - snprintf(buf, 4096, "%s\r\n", gopherState->request); + mb.appendf("query %s\r\nquit", t); } else { - snprintf(buf, 4096, "%s\r\n", gopherState->request); + if (gopherState->type_id == GOPHER_INDEX) { + if (char *t = strchr(gopherState->request, '?')) + *t = '\t'; + } + mb.append(gopherState->request, strlen(gopherState->request)); } + mb.append("\r\n", 2); - debugs(10, 5, HERE << gopherState->serverConn); + debugs(10, 5, gopherState->serverConn); AsyncCall::Pointer call = commCbCall(5,5, "gopherSendComplete", CommIoCbPtrFun(gopherSendComplete, gopherState)); - Comm::Write(gopherState->serverConn, buf, strlen(buf), call, NULL); + Comm::Write(gopherState->serverConn, &mb, call); gopherState->entry->makePublic(); } -- 2.47.2