This is an automated email from the ASF dual-hosted git repository. bcall pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.0.x by this push: new d879b3c Ran clang-tidy over the source tree (#7078) d879b3c is described below commit d879b3c970e9978d03bb957fc4dd9290c4c6f414 Author: Bryan Call <bc...@apache.org> AuthorDate: Thu Aug 6 15:47:53 2020 -0700 Ran clang-tidy over the source tree (#7078) --- example/plugins/cpp-api/websocket/WSBuffer.cc | 2 +- iocore/cache/Cache.cc | 2 +- iocore/cache/CacheLink.cc | 2 +- iocore/eventsystem/UnixEventProcessor.cc | 2 +- iocore/net/P_QUICNetVConnection.h | 4 +- iocore/net/P_QUICPacketHandler.h | 2 +- iocore/net/P_SSLUtils.h | 4 +- iocore/net/QUICNet.cc | 6 +- iocore/net/QUICNetVConnection.cc | 6 +- iocore/net/QUICPacketHandler.cc | 10 +-- iocore/net/SSLUtils.cc | 4 +- iocore/net/UnixNetVConnection.cc | 3 +- plugins/cache_promote/lru_policy.cc | 6 +- plugins/experimental/memcache/tsmemcache.cc | 3 +- plugins/experimental/metalink/metalink.cc | 15 ++-- plugins/experimental/remap_stats/remap_stats.cc | 2 +- plugins/experimental/slice/Config.cc | 8 +- plugins/experimental/slice/Range.cc | 2 +- plugins/experimental/slice/slice.cc | 2 +- plugins/experimental/slice/util.cc | 2 +- .../experimental/ssl_session_reuse/src/publish.cc | 16 ++-- .../ssl_session_reuse/src/session_process.cc | 2 +- .../experimental/stream_editor/stream_editor.cc | 12 +-- plugins/experimental/traffic_dump/session_data.cc | 4 +- .../experimental/traffic_dump/transaction_data.cc | 2 +- plugins/lua/ts_lua.c | 2 +- plugins/stats_over_http/stats_over_http.c | 3 +- proxy/ControlMatcher.cc | 6 +- proxy/ParentConsistentHash.cc | 3 +- proxy/hdrs/MIME.cc | 9 +- proxy/http/Http1Transaction.cc | 9 +- proxy/http/remap/NextHopConsistentHash.cc | 2 +- proxy/http/remap/NextHopSelectionStrategy.cc | 14 ++-- proxy/http/remap/NextHopStrategyFactory.cc | 16 ++-- proxy/http/remap/NextHopStrategyFactory.h | 2 +- proxy/logging/Log.cc | 2 +- proxy/logging/LogAccess.cc | 2 +- proxy/logging/LogFile.cc | 4 +- src/traffic_logstats/logstats.cc | 10 +-- src/traffic_server/FetchSM.cc | 2 +- src/traffic_server/InkAPITest.cc | 96 +++++++++++----------- src/tscore/ink_inet.cc | 12 +-- src/tscore/ink_queue.cc | 52 +++++++----- src/tscore/ink_res_init.cc | 15 ++-- src/tscore/ink_res_mkquery.cc | 3 +- src/tscore/unit_tests/test_Regex.cc | 8 +- tools/jtest/jtest.cc | 4 +- 47 files changed, 210 insertions(+), 189 deletions(-) diff --git a/example/plugins/cpp-api/websocket/WSBuffer.cc b/example/plugins/cpp-api/websocket/WSBuffer.cc index a53ac67..dce462d 100644 --- a/example/plugins/cpp-api/websocket/WSBuffer.cc +++ b/example/plugins/cpp-api/websocket/WSBuffer.cc @@ -113,7 +113,7 @@ WSBuffer::read_buffered_message(std::string &message, int &code) if (avail < 4 + mask_len) { // 2 + 2 + length bytes + mask. return false; } - msg_len = ntohs(*(uint16_t *)(ws_buf_.data() + 2)); + msg_len = ntohs(*reinterpret_cast<uint16_t *>(ws_buf_.data() + 2)); pos = 4; } else if (msg_len == WS_64BIT_LEN) { if (avail < 10 + mask_len) { // 2 + 8 length bytes + mask. diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc index ca3daf0..f84f50f 100644 --- a/iocore/cache/Cache.cc +++ b/iocore/cache/Cache.cc @@ -2774,7 +2774,7 @@ cplist_reconfigure() int64_t space_in_blks = 0; if (0 == tot_forced_space_in_blks) { // Calculate the space as percentage of total space in blocks. - space_in_blks = static_cast<int64_t>(((double)(config_vol->percent / percent_remaining)) * tot_space_in_blks); + space_in_blks = static_cast<int64_t>(((config_vol->percent / percent_remaining)) * tot_space_in_blks); } else { // Forced volumes take all disk space, so no percentage calculations here. space_in_blks = tot_forced_space_in_blks; diff --git a/iocore/cache/CacheLink.cc b/iocore/cache/CacheLink.cc index f8ae328..d3055f4 100644 --- a/iocore/cache/CacheLink.cc +++ b/iocore/cache/CacheLink.cc @@ -42,7 +42,7 @@ Cache::link(Continuation *cont, const CacheKey *from, const CacheKey *to, CacheF c->buf = new_IOBufferData(BUFFER_SIZE_INDEX_512); #ifdef DEBUG - Doc *doc = (Doc *)c->buf->data(); + Doc *doc = reinterpret_cast<Doc *>(c->buf->data()); memcpy(doc->data(), to, sizeof(*to)); // doublecheck #endif diff --git a/iocore/eventsystem/UnixEventProcessor.cc b/iocore/eventsystem/UnixEventProcessor.cc index c2f7fad..c3a30fe 100644 --- a/iocore/eventsystem/UnixEventProcessor.cc +++ b/iocore/eventsystem/UnixEventProcessor.cc @@ -193,7 +193,7 @@ ThreadAffinityInitializer::set_affinity(int, Event *) hwloc_obj_t obj = hwloc_get_obj_by_type(ink_get_topology(), obj_type, t->id % obj_count); #if HWLOC_API_VERSION >= 0x00010100 int cpu_mask_len = hwloc_bitmap_snprintf(nullptr, 0, obj->cpuset) + 1; - char *cpu_mask = (char *)alloca(cpu_mask_len); + char *cpu_mask = static_cast<char *>(alloca(cpu_mask_len)); hwloc_bitmap_snprintf(cpu_mask, cpu_mask_len, obj->cpuset); Debug("iocore_thread", "EThread: %p %s: %d CPU Mask: %s\n", t, obj_name, obj->logical_index, cpu_mask); #else diff --git a/iocore/net/P_QUICNetVConnection.h b/iocore/net/P_QUICNetVConnection.h index a3f24a4..484ea45 100644 --- a/iocore/net/P_QUICNetVConnection.h +++ b/iocore/net/P_QUICNetVConnection.h @@ -308,7 +308,7 @@ private: QUICPacketUPtr _packetize_frames(uint8_t *packet_buf, QUICEncryptionLevel level, uint64_t max_packet_size, std::vector<QUICFrameInfo> &frames); void _packetize_closing_frame(); - QUICPacketUPtr _build_packet(uint8_t *packet_buf, QUICEncryptionLevel level, Ptr<IOBufferBlock> parent_block, + QUICPacketUPtr _build_packet(uint8_t *packet_buf, QUICEncryptionLevel level, const Ptr<IOBufferBlock> &parent_block, bool retransmittable, bool probing, bool crypto); QUICConnectionErrorUPtr _recv_and_ack(const QUICPacketR &packet, bool *has_non_probing_frame = nullptr); @@ -358,7 +358,7 @@ private: void _update_local_cid(const QUICConnectionId &new_cid); void _rerandomize_original_cid(); - QUICHandshakeProtocol *_setup_handshake_protocol(shared_SSL_CTX ctx); + QUICHandshakeProtocol *_setup_handshake_protocol(const shared_SSL_CTX &ctx); QUICPacketUPtr _the_final_packet = QUICPacketFactory::create_null_packet(); uint8_t _final_packet_buf[QUICPacket::MAX_INSTANCE_SIZE]; diff --git a/iocore/net/P_QUICPacketHandler.h b/iocore/net/P_QUICPacketHandler.h index 4df92ec..3cf85ec 100644 --- a/iocore/net/P_QUICPacketHandler.h +++ b/iocore/net/P_QUICPacketHandler.h @@ -42,7 +42,7 @@ public: ~QUICPacketHandler(); void send_packet(const QUICPacket &packet, QUICNetVConnection *vc, const QUICPacketHeaderProtector &pn_protector); - void send_packet(QUICNetVConnection *vc, Ptr<IOBufferBlock> udp_payload); + void send_packet(QUICNetVConnection *vc, const Ptr<IOBufferBlock> &udp_payload); void close_connection(QUICNetVConnection *conn); diff --git a/iocore/net/P_SSLUtils.h b/iocore/net/P_SSLUtils.h index 5f0e402..46553dd 100644 --- a/iocore/net/P_SSLUtils.h +++ b/iocore/net/P_SSLUtils.h @@ -85,12 +85,12 @@ public: protected: const SSLConfigParams *_params; - bool _store_single_ssl_ctx(SSLCertLookup *lookup, shared_SSLMultiCertConfigParams sslMultCertSettings, shared_SSL_CTX ctx, + bool _store_single_ssl_ctx(SSLCertLookup *lookup, const shared_SSLMultiCertConfigParams &sslMultCertSettings, shared_SSL_CTX ctx, std::set<std::string> &names); private: virtual const char *_debug_tag() const; - bool _store_ssl_ctx(SSLCertLookup *lookup, shared_SSLMultiCertConfigParams ssl_multi_cert_params); + bool _store_ssl_ctx(SSLCertLookup *lookup, const shared_SSLMultiCertConfigParams &ssl_multi_cert_params); virtual void _set_handshake_callbacks(SSL_CTX *ctx); }; diff --git a/iocore/net/QUICNet.cc b/iocore/net/QUICNet.cc index 34e21ae..31d33d9 100644 --- a/iocore/net/QUICNet.cc +++ b/iocore/net/QUICNet.cc @@ -66,7 +66,7 @@ QUICPollCont::_process_long_header_packet(QUICPollEvent *e, NetHandler *nh) UDPPacketInternal *p = e->packet; // FIXME: VC is nullptr ? QUICNetVConnection *vc = static_cast<QUICNetVConnection *>(e->con); - uint8_t *buf = (uint8_t *)p->getIOBlockChain()->buf(); + uint8_t *buf = reinterpret_cast<uint8_t *>(p->getIOBlockChain()->buf()); QUICPacketType ptype; QUICLongHeaderPacketR::type(ptype, buf, 1); @@ -147,7 +147,7 @@ QUICPollCont::pollEvent(int, Event *) } while ((e = result.pop())) { - buf = (uint8_t *)e->packet->getIOBlockChain()->buf(); + buf = reinterpret_cast<uint8_t *>(e->packet->getIOBlockChain()->buf()); if (QUICInvariants::is_long_header(buf)) { // Long Header Packet with Connection ID, has a valid type value. this->_process_long_header_packet(e, nh); @@ -166,7 +166,7 @@ initialize_thread_for_quic_net(EThread *thread) NetHandler *nh = get_NetHandler(thread); QUICPollCont *quicpc = get_QUICPollCont(thread); - new ((ink_dummy_for_new *)quicpc) QUICPollCont(thread->mutex, nh); + new (reinterpret_cast<ink_dummy_for_new *>(quicpc)) QUICPollCont(thread->mutex, nh); thread->schedule_every(quicpc, -HRTIME_MSECONDS(UDP_PERIOD)); } diff --git a/iocore/net/QUICNetVConnection.cc b/iocore/net/QUICNetVConnection.cc index 3c129d9..9d7b643 100644 --- a/iocore/net/QUICNetVConnection.cc +++ b/iocore/net/QUICNetVConnection.cc @@ -1060,7 +1060,7 @@ QUICNetVConnection::select_next_protocol(SSL *ssl, const unsigned char **out, un if (this->getNPN(&npnptr, &npnsize)) { // SSL_select_next_proto chooses the first server-offered protocol that appears in the clients protocol set, ie. the // server selects the protocol. This is a n^2 search, so it's preferable to keep the protocol set short. - if (SSL_select_next_proto((unsigned char **)out, outlen, npnptr, npnsize, in, inlen) == OPENSSL_NPN_NEGOTIATED) { + if (SSL_select_next_proto(const_cast<unsigned char **>(out), outlen, npnptr, npnsize, in, inlen) == OPENSSL_NPN_NEGOTIATED) { Debug("ssl", "selected ALPN protocol %.*s", (int)(*outlen), *out); return SSL_TLSEXT_ERR_OK; } @@ -1754,7 +1754,7 @@ QUICNetVConnection::_recv_and_ack(const QUICPacketR &packet, bool *has_non_probi } QUICPacketUPtr -QUICNetVConnection::_build_packet(uint8_t *packet_buf, QUICEncryptionLevel level, Ptr<IOBufferBlock> parent_block, +QUICNetVConnection::_build_packet(uint8_t *packet_buf, QUICEncryptionLevel level, const Ptr<IOBufferBlock> &parent_block, bool ack_eliciting, bool probing, bool crypto) { QUICPacketType type = QUICTypeUtil::packet_type(level); @@ -2250,7 +2250,7 @@ QUICNetVConnection::_rerandomize_original_cid() } QUICHandshakeProtocol * -QUICNetVConnection::_setup_handshake_protocol(shared_SSL_CTX ctx) +QUICNetVConnection::_setup_handshake_protocol(const shared_SSL_CTX &ctx) { // Initialize handshake protocol specific stuff // For QUICv1 TLS is the only option diff --git a/iocore/net/QUICPacketHandler.cc b/iocore/net/QUICPacketHandler.cc index a6e214d..7c91351 100644 --- a/iocore/net/QUICPacketHandler.cc +++ b/iocore/net/QUICPacketHandler.cc @@ -177,7 +177,7 @@ QUICPacketHandlerIn::acceptEvent(int event, void *data) this->_collector_event = this_ethread()->schedule_every(this->_closed_con_collector, HRTIME_MSECONDS(100)); } - Queue<UDPPacket> *queue = (Queue<UDPPacket> *)data; + Queue<UDPPacket> *queue = static_cast<Queue<UDPPacket> *>(data); UDPPacket *packet_r; while ((packet_r = queue->dequeue())) { this->_recv_packet(event, packet_r); @@ -191,7 +191,7 @@ QUICPacketHandlerIn::acceptEvent(int event, void *data) if (((long)data) == -ECONNABORTED) { } - ink_abort("QUIC accept received fatal error: errno = %d", -((int)(intptr_t)data)); + ink_abort("QUIC accept received fatal error: errno = %d", -(static_cast<int>((intptr_t)data))); return EVENT_CONT; return 0; } @@ -386,7 +386,7 @@ QUICPacketHandler::send_packet(const QUICPacket &packet, QUICNetVConnection *vc, } void -QUICPacketHandler::send_packet(QUICNetVConnection *vc, Ptr<IOBufferBlock> udp_payload) +QUICPacketHandler::send_packet(QUICNetVConnection *vc, const Ptr<IOBufferBlock> &udp_payload) { this->_send_packet(vc->get_udp_con(), vc->con.addr, udp_payload); } @@ -493,7 +493,7 @@ QUICPacketHandlerIn::_send_invalid_token_error(const uint8_t *initial_packet, ui QUICConnectionId scid; scid.randomize(); uint8_t packet_buf[QUICPacket::MAX_INSTANCE_SIZE]; - QUICPacketUPtr cc_packet = pf.create_initial_packet(packet_buf, scid_in_initial, scid, 0, block, block_len, 0, 0, 1); + QUICPacketUPtr cc_packet = pf.create_initial_packet(packet_buf, scid_in_initial, scid, 0, block, block_len, false, false, true); this->_send_packet(*cc_packet, connection, from, 0, &php, scid_in_initial); } @@ -521,7 +521,7 @@ QUICPacketHandlerOut::event_handler(int event, Event *data) return EVENT_CONT; } case NET_EVENT_DATAGRAM_READ_READY: { - Queue<UDPPacket> *queue = (Queue<UDPPacket> *)data; + Queue<UDPPacket> *queue = reinterpret_cast<Queue<UDPPacket> *>(data); UDPPacket *packet_r; while ((packet_r = queue->dequeue())) { this->_recv_packet(event, packet_r); diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc index b3f5424..b3ee806 100644 --- a/iocore/net/SSLUtils.cc +++ b/iocore/net/SSLUtils.cc @@ -1393,7 +1393,7 @@ SSLCreateServerContext(const SSLConfigParams *params, const SSLMultiCertConfigPa Do NOT call SSL_CTX_set_* functions from here. SSL_CTX should be set up by SSLMultiCertConfigLoader::init_server_ssl_ctx(). */ bool -SSLMultiCertConfigLoader::_store_ssl_ctx(SSLCertLookup *lookup, const shared_SSLMultiCertConfigParams sslMultCertSettings) +SSLMultiCertConfigLoader::_store_ssl_ctx(SSLCertLookup *lookup, const shared_SSLMultiCertConfigParams &sslMultCertSettings) { bool retval = true; std::vector<X509 *> cert_list; @@ -1454,7 +1454,7 @@ SSLMultiCertConfigLoader::_store_ssl_ctx(SSLCertLookup *lookup, const shared_SSL } bool -SSLMultiCertConfigLoader::_store_single_ssl_ctx(SSLCertLookup *lookup, const shared_SSLMultiCertConfigParams sslMultCertSettings, +SSLMultiCertConfigLoader::_store_single_ssl_ctx(SSLCertLookup *lookup, const shared_SSLMultiCertConfigParams &sslMultCertSettings, shared_SSL_CTX ctx, std::set<std::string> &names) { bool inserted = false; diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc index a0e860b..c1c608b 100644 --- a/iocore/net/UnixNetVConnection.cc +++ b/iocore/net/UnixNetVConnection.cc @@ -290,8 +290,9 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) // Add data to buffer and signal continuation. buf.writer()->fill(r); #ifdef DEBUG - if (buf.writer()->write_avail() <= 0) + if (buf.writer()->write_avail() <= 0) { Debug("iocore_net", "read_from_net, read buffer full"); + } #endif s->vio.ndone += r; net_activity(vc, thread); diff --git a/plugins/cache_promote/lru_policy.cc b/plugins/cache_promote/lru_policy.cc index 34e498a..07eeef8 100644 --- a/plugins/cache_promote/lru_policy.cc +++ b/plugins/cache_promote/lru_policy.cc @@ -174,9 +174,9 @@ LRUPolicy::stats_add(const char *remap_id) return false; } - for (int ii = 0; ii < 8; ii++) { - std::string_view name = std::get<0>(stats[ii]); - int *id = std::get<1>(stats[ii]); + for (const auto &stat : stats) { + std::string_view name = std::get<0>(stat); + int *id = std::get<1>(stat); if ((*(id) = create_stat(name, remap_identifier)) == TS_ERROR) { return false; } diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc index 8e405d3..532c2bb 100644 --- a/plugins/experimental/memcache/tsmemcache.cc +++ b/plugins/experimental/memcache/tsmemcache.cc @@ -375,8 +375,9 @@ MC::write_binary_response(const void *d, int hlen, int keylen, int dlen) if (dlen) { MCDebug("tsmemcache", "response dlen %d\n", dlen); wbuf->write(d, dlen); - } else + } else { MCDebug("tsmemcache", "no response\n"); + } } return writer->read_avail(); } diff --git a/plugins/experimental/metalink/metalink.cc b/plugins/experimental/metalink/metalink.cc index fc97e14..9f7d201 100644 --- a/plugins/experimental/metalink/metalink.cc +++ b/plugins/experimental/metalink/metalink.cc @@ -44,19 +44,18 @@ /* TSCacheWrite() and TSVConnWrite() data: Write the digest to the * cache and store the request URL at that key */ -typedef struct { +struct WriteData { TSHttpTxn txnp; TSCacheKey key; TSVConn connp; TSIOBuffer cache_bufp; - -} WriteData; +}; /* TSTransformCreate() data: Compute the SHA-256 digest of the content */ -typedef struct { +struct TransformData { TSHttpTxn txnp; /* Null transformation */ @@ -65,13 +64,12 @@ typedef struct { /* Message digest handle */ SHA256_CTX c; - -} TransformData; +}; /* TSCacheRead() and TSVConnRead() data: Check the Location and Digest * headers */ -typedef struct { +struct SendData { TSHttpTxn txnp; TSMBuffer resp_bufp; @@ -95,8 +93,7 @@ typedef struct { const char *value; int64_t length; - -} SendData; +}; /* Implement TS_HTTP_READ_RESPONSE_HDR_HOOK to implement a null * transformation */ diff --git a/plugins/experimental/remap_stats/remap_stats.cc b/plugins/experimental/remap_stats/remap_stats.cc index 31809bb..727c752 100644 --- a/plugins/experimental/remap_stats/remap_stats.cc +++ b/plugins/experimental/remap_stats/remap_stats.cc @@ -110,7 +110,7 @@ get_effective_host(TSHttpTxn txn) int handle_read_req_hdr(TSCont cont, TSEvent event ATS_UNUSED, void *edata) { - TSHttpTxn txn = (TSHttpTxn)edata; + TSHttpTxn txn = static_cast<TSHttpTxn>(edata); config_t *config; void *txnd; diff --git a/plugins/experimental/slice/Config.cc b/plugins/experimental/slice/Config.cc index 17b7329..176ba94 100644 --- a/plugins/experimental/slice/Config.cc +++ b/plugins/experimental/slice/Config.cc @@ -150,7 +150,7 @@ Config::fromArgs(int const argc, char const *const argv[]) const char *errptr; int erroffset; m_regexstr = optarg; - m_regex = pcre_compile(m_regexstr.c_str(), 0, &errptr, &erroffset, NULL); + m_regex = pcre_compile(m_regexstr.c_str(), 0, &errptr, &erroffset, nullptr); if (nullptr == m_regex) { ERROR_LOG("Invalid regex: '%s'", m_regexstr.c_str()); } else { @@ -168,7 +168,7 @@ Config::fromArgs(int const argc, char const *const argv[]) const char *errptr; int erroffset; m_regexstr = optarg; - m_regex = pcre_compile(m_regexstr.c_str(), 0, &errptr, &erroffset, NULL); + m_regex = pcre_compile(m_regexstr.c_str(), 0, &errptr, &erroffset, nullptr); if (nullptr == m_regex) { ERROR_LOG("Invalid regex: '%s'", m_regexstr.c_str()); } else { @@ -264,12 +264,12 @@ Config::matchesRegex(char const *const url, int const urllen) const switch (m_regex_type) { case Exclude: { - if (0 <= pcre_exec(m_regex, m_regex_extra, url, urllen, 0, 0, NULL, 0)) { + if (0 <= pcre_exec(m_regex, m_regex_extra, url, urllen, 0, 0, nullptr, 0)) { matches = false; } } break; case Include: { - if (pcre_exec(m_regex, m_regex_extra, url, urllen, 0, 0, NULL, 0) < 0) { + if (pcre_exec(m_regex, m_regex_extra, url, urllen, 0, 0, nullptr, 0) < 0) { matches = false; } } break; diff --git a/plugins/experimental/slice/Range.cc b/plugins/experimental/slice/Range.cc index c0dfb04..c8c4fa3 100644 --- a/plugins/experimental/slice/Range.cc +++ b/plugins/experimental/slice/Range.cc @@ -156,7 +156,7 @@ int64_t Range::lastBlockFor(int64_t const blocksize) const { if (0 < blocksize && isValid()) { - return std::max((int64_t)0, (m_end - 1) / blocksize); + return std::max(static_cast<int64_t>(0), (m_end - 1) / blocksize); } else { return -1; } diff --git a/plugins/experimental/slice/slice.cc b/plugins/experimental/slice/slice.cc index f53fdd3..a091f5c 100644 --- a/plugins/experimental/slice/slice.cc +++ b/plugins/experimental/slice/slice.cc @@ -58,7 +58,7 @@ read_request(TSHttpTxn txnp, Config *const config) if (!header.hasKey(SLICER_MIME_FIELD_INFO, SLICER_MIME_LEN_INFO)) { // check if any previous plugin has monkeyed with the transaction status TSHttpStatus const txnstat = TSHttpTxnStatusGet(txnp); - if (0 != (int)txnstat) { + if (0 != static_cast<int>(txnstat)) { DEBUG_LOG("txn status change detected (%d), skipping plugin\n", (int)txnstat); return false; } diff --git a/plugins/experimental/slice/util.cc b/plugins/experimental/slice/util.cc index f3ae7d2..6f33559 100644 --- a/plugins/experimental/slice/util.cc +++ b/plugins/experimental/slice/util.cc @@ -78,7 +78,7 @@ request_block(TSCont contp, Data *const data) } // create virtual connection back into ATS - TSVConn const upvc = TSHttpConnectWithPluginId((sockaddr *)&data->m_client_ip, PLUGIN_NAME, 0); + TSVConn const upvc = TSHttpConnectWithPluginId(reinterpret_cast<sockaddr *>(&data->m_client_ip), PLUGIN_NAME, 0); int const hlen = TSHttpHdrLengthGet(header.m_buffer, header.m_lochdr); diff --git a/plugins/experimental/ssl_session_reuse/src/publish.cc b/plugins/experimental/ssl_session_reuse/src/publish.cc index 6aabf26..7c07a0a 100644 --- a/plugins/experimental/ssl_session_reuse/src/publish.cc +++ b/plugins/experimental/ssl_session_reuse/src/publish.cc @@ -35,7 +35,7 @@ #include "Config.h" #include "redis_auth.h" #include "ssl_utils.h" -#include <inttypes.h> +#include <cinttypes> #include <condition_variable> std::mutex q_mutex; @@ -93,8 +93,8 @@ RedisPublisher::RedisPublisher(const std::string &conf) m_redisPublishTries, m_redisConnectTries, m_redisRetryDelay, m_maxQueuedMessages); TSDebug(PLUGIN, "RedisPublisher::RedisPublisher: Redis Publish endpoints are as follows:"); - for (std::vector<RedisEndpoint>::iterator it = m_redisEndpoints.begin(); it != m_redisEndpoints.end(); ++it) { - simple_pool *pool = simple_pool::create(it->m_hostname, it->m_port, m_poolRedisConnectTimeout); + for (auto &m_redisEndpoint : m_redisEndpoints) { + simple_pool *pool = simple_pool::create(m_redisEndpoint.m_hostname, m_redisEndpoint.m_port, m_poolRedisConnectTimeout); pools.push_back(pool); } @@ -125,7 +125,7 @@ RedisPublisher::setup_connection(const RedisEndpoint &re) { uint64_t my_id = 0; if (TSIsDebugTagSet(PLUGIN)) { - my_id = (uint64_t)pthread_self(); + my_id = static_cast<uint64_t>(pthread_self()); TSDebug(PLUGIN, "RedisPublisher::setup_connection: Called by threadId: %" PRIx64, my_id); } @@ -175,7 +175,7 @@ RedisPublisher::send_publish(RedisContextPtr &ctx, const RedisEndpoint &re, cons { uint64_t my_id = 0; if (TSIsDebugTagSet(PLUGIN)) { - my_id = (uint64_t)pthread_self(); + my_id = static_cast<uint64_t>(pthread_self()); TSDebug(PLUGIN, "RedisPublisher::send_publish: Called by threadId: %" PRIx64, my_id); } @@ -266,7 +266,7 @@ RedisPublisher::runWorker() if (current_message.cleanup) { if (TSIsDebugTagSet(PLUGIN)) { - auto my_id = (uint64_t)pthread_self(); + auto my_id = static_cast<uint64_t>(pthread_self()); TSDebug(PLUGIN, "RedisPublisher::runWorker: threadId: %" PRIx64 " received the cleanup message. Exiting!", my_id); } break; @@ -360,7 +360,7 @@ std::string RedisPublisher::get_session(const std::string &channel) { if (TSIsDebugTagSet(PLUGIN)) { - auto my_id = (uint64_t)pthread_self(); + auto my_id = static_cast<uint64_t>(pthread_self()); TSDebug(PLUGIN, "RedisPublisher::get_session: Called by threadId: %" PRIx64, my_id); } @@ -396,7 +396,7 @@ redisReply * RedisPublisher::set_session(const Message &msg) { if (TSIsDebugTagSet(PLUGIN)) { - auto my_id = (uint64_t)pthread_self(); + auto my_id = static_cast<uint64_t>(pthread_self()); TSDebug(PLUGIN, "RedisPublisher::set_session: Called by threadId: %" PRIx64, my_id); } diff --git a/plugins/experimental/ssl_session_reuse/src/session_process.cc b/plugins/experimental/ssl_session_reuse/src/session_process.cc index e14cef8..a40b33c 100644 --- a/plugins/experimental/ssl_session_reuse/src/session_process.cc +++ b/plugins/experimental/ssl_session_reuse/src/session_process.cc @@ -112,7 +112,7 @@ decrypt_session(const std::string &encrypted_data, const unsigned char *key, int ssl_sess_ptr += sizeof(int64_t); // Length - ret = *(int32_t *)ssl_sess_ptr; + ret = *reinterpret_cast<int32_t *>(ssl_sess_ptr); ssl_sess_ptr += sizeof(int32_t); len_all = ret + sizeof(int64_t) + sizeof(int32_t); diff --git a/plugins/experimental/stream_editor/stream_editor.cc b/plugins/experimental/stream_editor/stream_editor.cc index e79ad08..839be9e 100644 --- a/plugins/experimental/stream_editor/stream_editor.cc +++ b/plugins/experimental/stream_editor/stream_editor.cc @@ -617,8 +617,8 @@ process_block(contdata_t *contdata, TSIOBufferReader reader) editset_t edits; - for (rule_p r = contdata->rules.begin(); r != contdata->rules.end(); ++r) { - r->apply(buf, buflen, edits); + for (const auto &rule : contdata->rules) { + rule.apply(buf, buflen, edits); } for (edit_p p = edits.begin(); p != edits.end(); ++p) { @@ -767,13 +767,13 @@ streamedit_setup(TSCont contp, TSEvent event, void *edata) assert((event == TS_EVENT_HTTP_READ_RESPONSE_HDR) || (event == TS_EVENT_HTTP_READ_REQUEST_HDR)); /* make a new list comprising those rules that are in scope */ - for (rule_p r = rules_in->begin(); r != rules_in->end(); ++r) { - if (r->in_scope(txn)) { + for (const auto &r : *rules_in) { + if (r.in_scope(txn)) { if (contdata == nullptr) { contdata = new contdata_t(); } - contdata->rules.push_back(*r); - contdata->set_cont_size(r->cont_size()); + contdata->rules.push_back(r); + contdata->set_cont_size(r.cont_size()); } } diff --git a/plugins/experimental/traffic_dump/session_data.cc b/plugins/experimental/traffic_dump/session_data.cc index e77c788..4c91f20 100644 --- a/plugins/experimental/traffic_dump/session_data.cc +++ b/plugins/experimental/traffic_dump/session_data.cc @@ -117,7 +117,7 @@ std::string get_tls_description_helper(TSVConn ssn_vc) { TSSslConnection ssl_conn = TSVConnSslConnectionGet(ssn_vc); - SSL *ssl_obj = (SSL *)ssl_conn; + SSL *ssl_obj = reinterpret_cast<SSL *>(ssl_conn); if (ssl_obj == nullptr) { return ""; } @@ -356,7 +356,7 @@ SessionData::global_session_handler(TSCont contp, TSEvent event, void *edata) if (!sni_filter.empty()) { TSVConn ssn_vc = TSHttpSsnClientVConnGet(ssnp); TSSslConnection ssl_conn = TSVConnSslConnectionGet(ssn_vc); - SSL *ssl_obj = (SSL *)ssl_conn; + SSL *ssl_obj = reinterpret_cast<SSL *>(ssl_conn); if (ssl_obj == nullptr) { TSDebug(debug_tag, "global_session_handler(): Ignore non-HTTPS session %" PRId64 "...", id); break; diff --git a/plugins/experimental/traffic_dump/transaction_data.cc b/plugins/experimental/traffic_dump/transaction_data.cc index b87a8c6..ec16fff 100644 --- a/plugins/experimental/traffic_dump/transaction_data.cc +++ b/plugins/experimental/traffic_dump/transaction_data.cc @@ -274,7 +274,7 @@ TransactionData::global_transaction_handler(TSCont contp, TSEvent event, void *e // The uuid is a header field for each message in the transaction. Use the // "all" node to apply to each message. std::string_view name = "uuid"; - txnData->txn_json += ",\"all\":{\"headers\":{\"fields\":[" + json_entry_array(name, uuid_view); + txnData->txn_json += R"(,"all":{"headers":{"fields":[)" + json_entry_array(name, uuid_view); txnData->txn_json += "]}}"; break; } diff --git a/plugins/lua/ts_lua.c b/plugins/lua/ts_lua.c index e23d578..1451c56 100644 --- a/plugins/lua/ts_lua.c +++ b/plugins/lua/ts_lua.c @@ -129,7 +129,7 @@ create_lua_vms() ts_lua_max_state_count = TS_LUA_MAX_STATE_COUNT; } else { ts_lua_max_state_count = (int)mgmt_state; - TSDebug(TS_LUA_DEBUG_TAG, "[%s] found %s: [%d]", __FUNCTION__, ts_lua_mgmt_state_str, (int)ts_lua_max_state_count); + TSDebug(TS_LUA_DEBUG_TAG, "[%s] found %s: [%d]", __FUNCTION__, ts_lua_mgmt_state_str, ts_lua_max_state_count); } if (ts_lua_max_state_count < 1) { diff --git a/plugins/stats_over_http/stats_over_http.c b/plugins/stats_over_http/stats_over_http.c index 1be2d54..9783e62 100644 --- a/plugins/stats_over_http/stats_over_http.c +++ b/plugins/stats_over_http/stats_over_http.c @@ -799,8 +799,9 @@ load_config_file(config_holder_t *config_holder) TSContScheduleOnPool(free_cont, FREE_TMOUT, TS_THREAD_POOL_TASK); } } - if (fh) + if (fh) { TSfclose(fh); + } return; } diff --git a/proxy/ControlMatcher.cc b/proxy/ControlMatcher.cc index 9695457..1b88922 100644 --- a/proxy/ControlMatcher.cc +++ b/proxy/ControlMatcher.cc @@ -664,10 +664,10 @@ void IpMatcher<Data, MatchResult>::Print() { printf("\tIp Matcher with %d elements, %zu ranges.\n", num_el, ip_map.count()); - for (IpMap::iterator spot(ip_map.begin()), limit(ip_map.end()); spot != limit; ++spot) { + for (auto &spot : ip_map) { char b1[INET6_ADDRSTRLEN], b2[INET6_ADDRSTRLEN]; - printf("\tRange %s - %s ", ats_ip_ntop(spot->min(), b1, sizeof b1), ats_ip_ntop(spot->max(), b2, sizeof b2)); - static_cast<Data *>(spot->data())->Print(); + printf("\tRange %s - %s ", ats_ip_ntop(spot.min(), b1, sizeof b1), ats_ip_ntop(spot.max(), b2, sizeof b2)); + static_cast<Data *>(spot.data())->Print(); } } diff --git a/proxy/ParentConsistentHash.cc b/proxy/ParentConsistentHash.cc index f7977d7..568fba9 100644 --- a/proxy/ParentConsistentHash.cc +++ b/proxy/ParentConsistentHash.cc @@ -121,8 +121,9 @@ chash_lookup(ATSConsistentHash *fhash, uint64_t path_hash, ATSConsistentHashIter // Do not set wrap_around to true until we try all the parents atleast once. bool wrapped = *wrap_around; *wrap_around = (*mapWrapped && *wrap_around) ? true : false; - if (!*mapWrapped && wrapped) + if (!*mapWrapped && wrapped) { *mapWrapped = true; + } return prtmp; } diff --git a/proxy/hdrs/MIME.cc b/proxy/hdrs/MIME.cc index db3cdd7..c2e938d 100644 --- a/proxy/hdrs/MIME.cc +++ b/proxy/hdrs/MIME.cc @@ -630,8 +630,9 @@ mime_hdr_sanity_check(MIMEHdrImpl *mh) if (field->m_next_dup) { bool found = false; for (blk = &(mh->m_first_fblock); blk != nullptr; blk = blk->m_next) { - const char *addr = (const char *)(field->m_next_dup); - if ((addr >= (const char *)(blk)) && (addr < (const char *)(blk) + sizeof(MIMEFieldBlockImpl))) { + const char *addr = reinterpret_cast<const char *>(field->m_next_dup); + if ((addr >= reinterpret_cast<const char *>(blk)) && + (addr < reinterpret_cast<const char *>(blk) + sizeof(MIMEFieldBlockImpl))) { found = true; break; } @@ -1664,8 +1665,8 @@ mime_hdr_field_delete(HdrHeap *heap, MIMEHdrImpl *mh, MIMEField *field, bool del if (prev_block != nullptr) { if (fblock->m_freetop == MIME_FIELD_BLOCK_SLOTS && fblock->contains(field)) { // Check if fields in all slots are deleted - for (int i = 0; i < MIME_FIELD_BLOCK_SLOTS; ++i) { - if (fblock->m_field_slots[i].m_readiness != MIME_FIELD_SLOT_READINESS_DELETED) { + for (auto &m_field_slot : fblock->m_field_slots) { + if (m_field_slot.m_readiness != MIME_FIELD_SLOT_READINESS_DELETED) { can_destroy_block = false; break; } diff --git a/proxy/http/Http1Transaction.cc b/proxy/http/Http1Transaction.cc index 5d07691..d2f8b2c 100644 --- a/proxy/http/Http1Transaction.cc +++ b/proxy/http/Http1Transaction.cc @@ -117,20 +117,23 @@ Http1Transaction::do_io_shutdown(ShutdownHowTo_t howto) void Http1Transaction::set_active_timeout(ink_hrtime timeout_in) { - if (_proxy_ssn) + if (_proxy_ssn) { _proxy_ssn->set_active_timeout(timeout_in); + } } void Http1Transaction::set_inactivity_timeout(ink_hrtime timeout_in) { - if (_proxy_ssn) + if (_proxy_ssn) { _proxy_ssn->set_inactivity_timeout(timeout_in); + } } void Http1Transaction::cancel_inactivity_timeout() { - if (_proxy_ssn) + if (_proxy_ssn) { _proxy_ssn->cancel_inactivity_timeout(); + } } // int diff --git a/proxy/http/remap/NextHopConsistentHash.cc b/proxy/http/remap/NextHopConsistentHash.cc index f36605c..b28a6c1 100644 --- a/proxy/http/remap/NextHopConsistentHash.cc +++ b/proxy/http/remap/NextHopConsistentHash.cc @@ -35,7 +35,7 @@ constexpr std::string_view hash_key_path_fragment = "path+fragment"; constexpr std::string_view hash_key_cache = "cache_key"; static HostRecord * -chash_lookup(std::shared_ptr<ATSConsistentHash> ring, uint64_t hash_key, ATSConsistentHashIter *iter, bool *wrapped, +chash_lookup(const std::shared_ptr<ATSConsistentHash> &ring, uint64_t hash_key, ATSConsistentHashIter *iter, bool *wrapped, ATSHash64Sip24 *hash, bool *hash_init, bool *mapWrapped, uint64_t sm_id) { HostRecord *host_rec = nullptr; diff --git a/proxy/http/remap/NextHopSelectionStrategy.cc b/proxy/http/remap/NextHopSelectionStrategy.cc index 0507350..20d6a39 100644 --- a/proxy/http/remap/NextHopSelectionStrategy.cc +++ b/proxy/http/remap/NextHopSelectionStrategy.cc @@ -107,8 +107,8 @@ NextHopSelectionStrategy::Init(const YAML::Node &n) NH_Error("Error in the response_codes definition for the strategy named '%s', skipping response_codes.", strategy_name.c_str()); } else { - for (unsigned int k = 0; k < resp_codes_node.size(); ++k) { - auto code = resp_codes_node[k].as<int>(); + for (auto &&k : resp_codes_node) { + auto code = k.as<int>(); if (code > 300 && code < 599) { resp_codes.add(code); } else { @@ -293,8 +293,8 @@ bool NextHopSelectionStrategy::nextHopExists(const uint64_t sm_id) { for (uint32_t gg = 0; gg < groups; gg++) { - for (uint32_t hh = 0; hh < host_groups[gg].size(); hh++) { - HostRecord *p = host_groups[gg][hh].get(); + for (auto &hh : host_groups[gg]) { + HostRecord *p = hh.get(); if (p->available) { NH_Debug(NH_DEBUG_TAG, "[%" PRIu64 "] found available next hop %s", sm_id, p->hostname.c_str()); return true; @@ -334,9 +334,9 @@ template <> struct convert<HostRecord> { if (proto.Type() != YAML::NodeType::Sequence) { throw std::invalid_argument("Invalid host protocol definition, expected a sequence."); } else { - for (unsigned int ii = 0; ii < proto.size(); ii++) { - YAML::Node protocol_node = proto[ii]; - std::shared_ptr<NHProtocol> pr = std::make_shared<NHProtocol>(protocol_node.as<NHProtocol>()); + for (auto &&ii : proto) { + const YAML::Node &protocol_node = ii; + std::shared_ptr<NHProtocol> pr = std::make_shared<NHProtocol>(protocol_node.as<NHProtocol>()); nh.protocols.push_back(std::move(pr)); } } diff --git a/proxy/http/remap/NextHopStrategyFactory.cc b/proxy/http/remap/NextHopStrategyFactory.cc index 1bfc9ec..4de0b8a 100644 --- a/proxy/http/remap/NextHopStrategyFactory.cc +++ b/proxy/http/remap/NextHopStrategyFactory.cc @@ -24,7 +24,7 @@ #include <yaml-cpp/yaml.h> #include <fstream> -#include <string.h> +#include <cstring> #include "NextHopStrategyFactory.h" #include "NextHopConsistentHash.h" @@ -65,15 +65,15 @@ NextHopStrategyFactory::NextHopStrategyFactory(const char *file) } } // loop through the strategies document. - for (unsigned int i = 0; i < strategies.size(); ++i) { - YAML::Node strategy = strategies[i]; + for (auto &&strategie : strategies) { + YAML::Node strategy = strategie; auto name = strategy["strategy"].as<std::string>(); auto policy = strategy["policy"]; if (!policy) { NH_Error("No policy is defined for the strategy named '%s', this strategy will be ignored.", name.c_str()); continue; } - auto policy_value = policy.Scalar(); + const auto &policy_value = policy.Scalar(); NHPolicyType policy_type = NH_UNDEFINED; if (policy_value == consistent_hash) { @@ -175,7 +175,7 @@ NextHopStrategyFactory::strategyInstance(const char *name) * 'strategy' yaml file would then normally have the '#include hosts.yml' in it's begining. */ void -NextHopStrategyFactory::loadConfigFile(const std::string fileName, std::stringstream &doc, +NextHopStrategyFactory::loadConfigFile(const std::string &fileName, std::stringstream &doc, std::unordered_set<std::string> &include_once) { const char *sep = " \t"; @@ -214,8 +214,8 @@ NextHopStrategyFactory::loadConfigFile(const std::string fileName, std::stringst std::sort(files.begin(), files.end(), [](const std::string_view lhs, const std::string_view rhs) { return lhs.compare(rhs) < 0; }); - for (uint32_t i = 0; i < files.size(); i++) { - std::ifstream file(fileName + "/" + files[i].data()); + for (auto &i : files) { + std::ifstream file(fileName + "/" + i.data()); if (file.is_open()) { while (std::getline(file, line)) { if (line[0] == '#') { @@ -225,7 +225,7 @@ NextHopStrategyFactory::loadConfigFile(const std::string fileName, std::stringst } file.close(); } else { - throw std::invalid_argument("Unable to open and read '" + fileName + "/" + files[i].data() + "'"); + throw std::invalid_argument("Unable to open and read '" + fileName + "/" + i.data() + "'"); } } } diff --git a/proxy/http/remap/NextHopStrategyFactory.h b/proxy/http/remap/NextHopStrategyFactory.h index 3ef5cdc..ecb25a8 100644 --- a/proxy/http/remap/NextHopStrategyFactory.h +++ b/proxy/http/remap/NextHopStrategyFactory.h @@ -48,7 +48,7 @@ public: private: std::string fn; - void loadConfigFile(const std::string file, std::stringstream &doc, std::unordered_set<std::string> &include_once); + void loadConfigFile(const std::string &file, std::stringstream &doc, std::unordered_set<std::string> &include_once); void createStrategy(const std::string &name, const NHPolicyType policy_type, const YAML::Node &node); std::unordered_map<std::string, std::shared_ptr<NextHopSelectionStrategy>> _strategies; }; diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc index 33da376..fe4afa3 100644 --- a/proxy/logging/Log.cc +++ b/proxy/logging/Log.cc @@ -943,7 +943,7 @@ Log::init_fields() field_symbol_hash.emplace("ppdip", field); field = new LogField("version_build_number", "vbn", LogField::STRING, &LogAccess::marshal_version_build_number, - (LogField::UnmarshalFunc)&LogAccess::unmarshal_str); + reinterpret_cast<LogField::UnmarshalFunc>(&LogAccess::unmarshal_str)); global_field_list.add(field, false); field_symbol_hash.emplace("vbn", field); diff --git a/proxy/logging/LogAccess.cc b/proxy/logging/LogAccess.cc index 6aeae95..a394c08 100644 --- a/proxy/logging/LogAccess.cc +++ b/proxy/logging/LogAccess.cc @@ -354,7 +354,7 @@ LogAccess::marshal_str(char *dest, const char *source, int padded_len) // bytes to avoid UMR errors when the buffer is written. // size_t real_len = (::strlen(source) + 1); - while ((int)real_len < padded_len) { + while (static_cast<int>(real_len) < padded_len) { dest[real_len] = '$'; real_len++; } diff --git a/proxy/logging/LogFile.cc b/proxy/logging/LogFile.cc index 26fcca6..89bdc80 100644 --- a/proxy/logging/LogFile.cc +++ b/proxy/logging/LogFile.cc @@ -197,7 +197,7 @@ LogFile::open_file() #ifdef F_GETPIPE_SZ // adjust pipe size if necessary if (m_pipe_buffer_size) { - long pipe_size = (long)fcntl(m_fd, F_GETPIPE_SZ); + long pipe_size = static_cast<long>(fcntl(m_fd, F_GETPIPE_SZ)); if (pipe_size == -1) { Error("Get pipe size failed for pipe %s: %s", m_name, strerror(errno)); } else { @@ -209,7 +209,7 @@ LogFile::open_file() Error("Set pipe size failed for pipe %s to size %d: %s", m_name, m_pipe_buffer_size, strerror(errno)); } - pipe_size = (long)fcntl(m_fd, F_GETPIPE_SZ); + pipe_size = static_cast<long>(fcntl(m_fd, F_GETPIPE_SZ)); if (pipe_size == -1) { Error("Get pipe size after setting it failed for pipe %s: %s", m_name, strerror(errno)); } else { diff --git a/src/traffic_logstats/logstats.cc b/src/traffic_logstats/logstats.cc index 53be58e..c581e1f 100644 --- a/src/traffic_logstats/logstats.cc +++ b/src/traffic_logstats/logstats.cc @@ -336,10 +336,10 @@ struct hash_fnv32 { } }; -using LruStack = std::list<UrlStats>; -typedef std::unordered_map<const char *, OriginStats *, hash_fnv32, eqstr> OriginStorage; -typedef std::unordered_set<const char *, hash_fnv32, eqstr> OriginSet; -typedef std::unordered_map<const char *, LruStack::iterator, hash_fnv32, eqstr> LruHash; +using LruStack = std::list<UrlStats>; +using OriginStorage = std::unordered_map<const char *, OriginStats *, hash_fnv32, eqstr>; +using OriginSet = std::unordered_set<const char *, hash_fnv32, eqstr>; +using LruHash = std::unordered_map<const char *, LruStack::iterator, hash_fnv32, eqstr>; // Resize a hash-based container. template <class T, class N> @@ -1998,7 +1998,7 @@ format_line(const char *desc, const StatsCounter &stat, const StatsCounter &tota } // Little "helpers" for the vector we use to sort the Origins. -typedef pair<const char *, OriginStats *> OriginPair; +using OriginPair = pair<const char *, OriginStats *>; inline bool operator<(const OriginPair &a, const OriginPair &b) { diff --git a/src/traffic_server/FetchSM.cc b/src/traffic_server/FetchSM.cc index 0cb2919..aa73597 100644 --- a/src/traffic_server/FetchSM.cc +++ b/src/traffic_server/FetchSM.cc @@ -389,7 +389,7 @@ FetchSM::get_info_from_buffer(IOBufferReader *reader) if (header_done == 0 && read_done > 0) { int bytes_used = 0; - header_done = 1; + header_done = true; if (client_response_hdr.parse_resp(&http_parser, reader, &bytes_used, 0) == PARSE_RESULT_DONE) { if ((bytes_used > 0) && (bytes_used <= read_avail)) { memcpy(info, buf, bytes_used); diff --git a/src/traffic_server/InkAPITest.cc b/src/traffic_server/InkAPITest.cc index 1b0bad1..2b13745 100644 --- a/src/traffic_server/InkAPITest.cc +++ b/src/traffic_server/InkAPITest.cc @@ -90,7 +90,7 @@ using TxnHandler = int (*)(TSCont, TSEvent, void *); /* Server transaction structure */ -typedef struct { +struct ServerTxn { TSVConn vconn; TSVIO read_vio; @@ -106,24 +106,24 @@ typedef struct { TxnHandler current_handler; unsigned int magic; -} ServerTxn; +}; /* Server structure */ -typedef struct { +struct SocketServer { int accept_port; TSAction accept_action; TSCont accept_cont; unsigned int magic; -} SocketServer; +}; -typedef enum { +enum RequestStatus { REQUEST_SUCCESS, REQUEST_INPROGRESS, REQUEST_FAILURE, -} RequestStatus; +}; /* Client structure */ -typedef struct { +struct ClientTxn { TSVConn vconn; TSVIO read_vio; @@ -148,7 +148,7 @@ typedef struct { TxnHandler current_handler; unsigned int magic; -} ClientTxn; +}; ////////////////////////////////////////////////////////////////////////////// // DECLARATIONS @@ -1597,7 +1597,7 @@ int *SDK_Cache_pstatus; static char content[OBJECT_SIZE]; static int read_counter = 0; -typedef struct { +struct CacheVConnStruct { TSIOBuffer bufp; TSIOBuffer out_bufp; TSIOBufferReader readerp; @@ -1609,7 +1609,7 @@ typedef struct { TSVIO write_vio; TSCacheKey key; -} CacheVConnStruct; +}; int cache_handler(TSCont contp, TSEvent event, void *data) @@ -2527,10 +2527,10 @@ static RegressionTest *SDK_ContData_test; static int *SDK_ContData_pstatus; // this is specific for this test -typedef struct { +struct MyData { int data1; int data2; -} MyData; +}; int cont_data_handler(TSCont contp, TSEvent /* event ATS_UNUSED */, void * /* edata ATS_UNUSED */) @@ -3038,7 +3038,7 @@ REGRESSION_TEST(SDK_API_TSContSchedule)(RegressionTest *test, int /* atype ATS_U #define HTTP_HOOK_TEST_REQUEST_ID 1 -typedef struct { +struct SocketTest { RegressionTest *regtest; int *pstatus; SocketServer *os; @@ -3058,7 +3058,7 @@ typedef struct { bool test_client_protocol_stack_contains; unsigned int magic; -} SocketTest; +}; // This func is called by us from mytest_handler to test TSHttpTxnClientIPGet static int @@ -6292,13 +6292,13 @@ REGRESSION_TEST(SDK_API_TSUrlParse)(RegressionTest *test, int /* atype ATS_UNUSE ////////////////////////////////////////////// #define LOG_TEST_PATTERN "SDK team rocks" -typedef struct { +struct LogTestData { RegressionTest *test; int *pstatus; char *fullpath_logname; unsigned long magic; TSTextLogObject log; -} LogTestData; +}; static int log_test_handler(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */) @@ -6527,19 +6527,19 @@ REGRESSION_TEST(SDK_API_TSMgmtGet)(RegressionTest *test, int /* atype ATS_UNUSED } \ } -typedef enum { +enum ORIG_TSParseResult { ORIG_TS_PARSE_ERROR = -1, ORIG_TS_PARSE_DONE = 0, ORIG_TS_PARSE_CONT = 1, -} ORIG_TSParseResult; +}; -typedef enum { +enum ORIG_TSHttpType { ORIG_TS_HTTP_TYPE_UNKNOWN, ORIG_TS_HTTP_TYPE_REQUEST, ORIG_TS_HTTP_TYPE_RESPONSE, -} ORIG_TSHttpType; +}; -typedef enum { +enum ORIG_TSHttpStatus { ORIG_TS_HTTP_STATUS_NONE = 0, ORIG_TS_HTTP_STATUS_CONTINUE = 100, @@ -6584,9 +6584,9 @@ typedef enum { ORIG_TS_HTTP_STATUS_SERVICE_UNAVAILABLE = 503, ORIG_TS_HTTP_STATUS_GATEWAY_TIMEOUT = 504, ORIG_TS_HTTP_STATUS_HTTPVER_NOT_SUPPORTED = 505 -} ORIG_TSHttpStatus; +}; -typedef enum { +enum ORIG_TSHttpHookID { ORIG_TS_HTTP_READ_REQUEST_HDR_HOOK, ORIG_TS_HTTP_OS_DNS_HOOK, ORIG_TS_HTTP_SEND_REQUEST_HDR_HOOK, @@ -6618,9 +6618,9 @@ typedef enum { ORIG_TS_SSL_LAST_HOOK = ORIG_TS_VCONN_OUTBOUND_CLOSE_HOOK, ORIG_TS_HTTP_REQUEST_BUFFER_READ_COMPLETE_HOOK, ORIG_TS_HTTP_LAST_HOOK -} ORIG_TSHttpHookID; +}; -typedef enum { +enum ORIG_TSEvent { ORIG_TS_EVENT_NONE = 0, ORIG_TS_EVENT_IMMEDIATE = 1, ORIG_TS_EVENT_TIMEOUT = 2, @@ -6671,44 +6671,44 @@ typedef enum { ORIG_TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE = 60015, ORIG_TS_EVENT_MGMT_UPDATE = 60300 -} ORIG_TSEvent; +}; -typedef enum { +enum ORIG_TSCacheLookupResult { ORIG_TS_CACHE_LOOKUP_MISS, ORIG_TS_CACHE_LOOKUP_HIT_STALE, ORIG_TS_CACHE_LOOKUP_HIT_FRESH, -} ORIG_TSCacheLookupResult; +}; -typedef enum { +enum ORIG_TSCacheDataType { ORIG_TS_CACHE_DATA_TYPE_NONE, ORIG_TS_CACHE_DATA_TYPE_HTTP, ORIG_TS_CACHE_DATA_TYPE_OTHER, -} ORIG_TSCacheDataType; +}; -typedef enum { +enum ORIG_TSCacheError { ORIG_TS_CACHE_ERROR_NO_DOC = -20400, ORIG_TS_CACHE_ERROR_DOC_BUSY = -20401, ORIG_TS_CACHE_ERROR_NOT_READY = -20407 -} ORIG_TSCacheError; +}; -typedef enum { +enum ORIG_TSCacheScanResult { ORIG_TS_CACHE_SCAN_RESULT_DONE = 0, ORIG_TS_CACHE_SCAN_RESULT_CONTINUE = 1, ORIG_TS_CACHE_SCAN_RESULT_DELETE = 10, ORIG_TS_CACHE_SCAN_RESULT_DELETE_ALL_ALTERNATES, ORIG_TS_CACHE_SCAN_RESULT_UPDATE, ORIG_TS_CACHE_SCAN_RESULT_RETRY -} ORIG_TSCacheScanResult; +}; -typedef enum { +enum ORIG_TSVConnCloseFlags { ORIG_TS_VC_CLOSE_ABORT = -1, ORIG_TS_VC_CLOSE_NORMAL = 1, -} ORIG_TSVConnCloseFlags; +}; -typedef enum { +enum ORIG_TSReturnCode { ORIG_TS_ERROR = -1, ORIG_TS_SUCCESS = 0, -} ORIG_TSReturnCode; +}; REGRESSION_TEST(SDK_API_TSConstant)(RegressionTest *test, int /* atype ATS_UNUSED */, int *pstatus) { @@ -6868,7 +6868,7 @@ REGRESSION_TEST(SDK_API_TSConstant)(RegressionTest *test, int /* atype ATS_UNUSE // TSHttpTxnParentProxySet ////////////////////////////////////////////// -typedef struct { +struct ContData { RegressionTest *test; int *pstatus; SocketServer *os; @@ -6881,7 +6881,7 @@ typedef struct { int test_passed_txn_error_body_set; bool test_passed_Parent_Proxy; int magic; -} ContData; +}; static int checkHttpTxnParentProxy(ContData *data, TSHttpTxn txnp) @@ -7347,7 +7347,7 @@ EXCLUSIVE_REGRESSION_TEST(SDK_API_HttpParentProxySet_Success)(RegressionTest *te // TSHttpTxnCacheLookupStatusGet ///////////////////////////////////////////////////// -typedef struct { +struct CacheTestData { RegressionTest *test; int *pstatus; SocketServer *os; @@ -7359,7 +7359,7 @@ typedef struct { bool test_passed_txn_cache_lookup_status; bool first_time; int magic; -} CacheTestData; +}; static int cache_hook_handler(TSCont contp, TSEvent event, void *edata) @@ -7566,7 +7566,7 @@ EXCLUSIVE_REGRESSION_TEST(SDK_API_HttpTxnCache)(RegressionTest *test, int /* aty /** Append Transform Data Structure Ends **/ -typedef struct { +struct TransformTestData { RegressionTest *test; int *pstatus; SocketServer *os; @@ -7582,7 +7582,7 @@ typedef struct { bool test_passed_transform_create; int req_no; uint32_t magic; -} TransformTestData; +}; /** Append Transform Data Structure **/ struct AppendTransformTestData { @@ -8101,7 +8101,7 @@ EXCLUSIVE_REGRESSION_TEST(SDK_API_HttpTxnTransform)(RegressionTest *test, int /* // TSHttpTxnCachedRespGet ////////////////////////////////////////////// -typedef struct { +struct AltInfoTestData { RegressionTest *test; int *pstatus; SocketServer *os; @@ -8118,7 +8118,7 @@ typedef struct { bool run_at_least_once; bool first_time; int magic; -} AltInfoTestData; +}; static int altinfo_hook_handler(TSCont contp, TSEvent event, void *edata) @@ -8336,7 +8336,7 @@ EXCLUSIVE_REGRESSION_TEST(SDK_API_HttpAltInfo)(RegressionTest *test, int /* atyp #define TEST_CASE_CONNECT_ID1 9 // TSHttpTxnIntercept #define TEST_CASE_CONNECT_ID2 10 // TSHttpTxnServerIntercept -typedef struct { +struct ConnectTestData { RegressionTest *test; int *pstatus; int test_case; @@ -8345,7 +8345,7 @@ typedef struct { ClientTxn *browser; char *request; unsigned long magic; -} ConnectTestData; +}; static int cont_test_handler(TSCont contp, TSEvent event, void *edata) diff --git a/src/tscore/ink_inet.cc b/src/tscore/ink_inet.cc index 5ba9bc3..9d1dff7 100644 --- a/src/tscore/ink_inet.cc +++ b/src/tscore/ink_inet.cc @@ -64,7 +64,7 @@ ink_inet_addr(const char *s) uint32_t base = 10; if (nullptr == s) { - return htonl((uint32_t)-1); + return htonl(static_cast<uint32_t>(-1)); } while (n < 4) { @@ -103,7 +103,7 @@ ink_inet_addr(const char *s) } if (*pc && !ParseRules::is_wslfcr(*pc)) { - return htonl((uint32_t)-1); + return htonl(static_cast<uint32_t>(-1)); } switch (n) { @@ -111,21 +111,21 @@ ink_inet_addr(const char *s) return htonl(u[0]); case 2: if (u[0] > 0xff || u[1] > 0xffffff) { - return htonl((uint32_t)-1); + return htonl(static_cast<uint32_t>(-1)); } return htonl((u[0] << 24) | u[1]); case 3: if (u[0] > 0xff || u[1] > 0xff || u[2] > 0xffff) { - return htonl((uint32_t)-1); + return htonl(static_cast<uint32_t>(-1)); } return htonl((u[0] << 24) | (u[1] << 16) | u[2]); case 4: if (u[0] > 0xff || u[1] > 0xff || u[2] > 0xff || u[3] > 0xff) { - return htonl((uint32_t)-1); + return htonl(static_cast<uint32_t>(-1)); } return htonl((u[0] << 24) | (u[1] << 16) | (u[2] << 8) | u[3]); } - return htonl((uint32_t)-1); + return htonl(static_cast<uint32_t>(-1)); } const char * diff --git a/src/tscore/ink_queue.cc b/src/tscore/ink_queue.cc index 22f3b32..f4a2841 100644 --- a/src/tscore/ink_queue.cc +++ b/src/tscore/ink_queue.cc @@ -227,9 +227,10 @@ freelist_new(InkFreeList *f) for (i = 0; i < f->chunk_size; i++) { char *a = (static_cast<char *>(FREELIST_POINTER(item))) + i * f->type_size; #ifdef DEADBEEF - const char str[4] = {(char)0xde, (char)0xad, (char)0xbe, (char)0xef}; - for (int j = 0; j < (int)f->type_size; j++) + const char str[4] = {static_cast<char>(0xde), static_cast<char>(0xad), static_cast<char>(0xbe), static_cast<char>(0xef)}; + for (int j = 0; j < static_cast<int>(f->type_size); j++) { a[j] = str[j % 4]; + } #endif freelist_free(f, a); } @@ -240,12 +241,15 @@ freelist_new(InkFreeList *f) #ifdef SANITY if (result) { - if (FREELIST_POINTER(item) == TO_PTR(FREELIST_POINTER(next))) + if (FREELIST_POINTER(item) == TO_PTR(FREELIST_POINTER(next))) { ink_abort("ink_freelist_new: loop detected"); - if (((uintptr_t)(TO_PTR(FREELIST_POINTER(next)))) & 3) + } + if (((uintptr_t)(TO_PTR(FREELIST_POINTER(next)))) & 3) { ink_abort("ink_freelist_new: bad list"); - if (TO_PTR(FREELIST_POINTER(next))) - fake_global_for_ink_queue = *(int *)TO_PTR(FREELIST_POINTER(next)); + } + if (TO_PTR(FREELIST_POINTER(next))) { + fake_global_for_ink_queue = *static_cast<int *>(TO_PTR(FREELIST_POINTER(next))); + } } #endif /* SANITY */ } @@ -291,23 +295,27 @@ freelist_free(InkFreeList *f, void *item) #ifdef DEADBEEF { - static const char str[4] = {(char)0xde, (char)0xad, (char)0xbe, (char)0xef}; + static const char str[4] = {static_cast<char>(0xde), static_cast<char>(0xad), static_cast<char>(0xbe), static_cast<char>(0xef)}; // set the entire item to DEADBEEF - for (int j = 0; j < (int)f->type_size; j++) - ((char *)item)[j] = str[j % 4]; + for (int j = 0; j < static_cast<int>(f->type_size); j++) { + (static_cast<char *>(item))[j] = str[j % 4]; + } } #endif /* DEADBEEF */ while (!result) { INK_QUEUE_LD(h, f->head); #ifdef SANITY - if (TO_PTR(FREELIST_POINTER(h)) == item) + if (TO_PTR(FREELIST_POINTER(h)) == item) { ink_abort("ink_freelist_free: trying to free item twice"); - if (((uintptr_t)(TO_PTR(FREELIST_POINTER(h)))) & 3) + } + if (((uintptr_t)(TO_PTR(FREELIST_POINTER(h)))) & 3) { ink_abort("ink_freelist_free: bad list"); - if (TO_PTR(FREELIST_POINTER(h))) - fake_global_for_ink_queue = *(int *)TO_PTR(FREELIST_POINTER(h)); + } + if (TO_PTR(FREELIST_POINTER(h))) { + fake_global_for_ink_queue = *static_cast<int *>(TO_PTR(FREELIST_POINTER(h))); + } #endif /* SANITY */ *adr_of_next = FREELIST_POINTER(h); SET_FREELIST_POINTER_VERSION(item_pair, FROM_PTR(item), FREELIST_VERSION(h)); @@ -347,13 +355,14 @@ freelist_bulkfree(InkFreeList *f, void *head, void *tail, size_t num_item) #ifdef DEADBEEF { - static const char str[4] = {(char)0xde, (char)0xad, (char)0xbe, (char)0xef}; + static const char str[4] = {static_cast<char>(0xde), static_cast<char>(0xad), static_cast<char>(0xbe), static_cast<char>(0xef)}; // set the entire item to DEADBEEF; void *temp = head; for (size_t i = 0; i < num_item; i++) { - for (int j = sizeof(void *); j < (int)f->type_size; j++) - ((char *)temp)[j] = str[j % 4]; + for (int j = sizeof(void *); j < static_cast<int>(f->type_size); j++) { + (static_cast<char *>(temp))[j] = str[j % 4]; + } *ADDRESS_OF_NEXT(temp, 0) = FROM_PTR(*ADDRESS_OF_NEXT(temp, 0)); temp = TO_PTR(*ADDRESS_OF_NEXT(temp, 0)); } @@ -363,12 +372,15 @@ freelist_bulkfree(InkFreeList *f, void *head, void *tail, size_t num_item) while (!result) { INK_QUEUE_LD(h, f->head); #ifdef SANITY - if (TO_PTR(FREELIST_POINTER(h)) == head) + if (TO_PTR(FREELIST_POINTER(h)) == head) { ink_abort("ink_freelist_free: trying to free item twice"); - if (((uintptr_t)(TO_PTR(FREELIST_POINTER(h)))) & 3) + } + if (((uintptr_t)(TO_PTR(FREELIST_POINTER(h)))) & 3) { ink_abort("ink_freelist_free: bad list"); - if (TO_PTR(FREELIST_POINTER(h))) - fake_global_for_ink_queue = *(int *)TO_PTR(FREELIST_POINTER(h)); + } + if (TO_PTR(FREELIST_POINTER(h))) { + fake_global_for_ink_queue = *static_cast<int *>(TO_PTR(FREELIST_POINTER(h))); + } #endif /* SANITY */ *adr_of_next = FREELIST_POINTER(h); SET_FREELIST_POINTER_VERSION(item_pair, FROM_PTR(head), FREELIST_VERSION(h)); diff --git a/src/tscore/ink_res_init.cc b/src/tscore/ink_res_init.cc index be4dccc..fd293c7 100644 --- a/src/tscore/ink_res_init.cc +++ b/src/tscore/ink_res_init.cc @@ -168,8 +168,9 @@ ink_res_setoptions(ink_res_state statp, const char *options, const char *source int i; #ifdef DEBUG - if (statp->options & INK_RES_DEBUG) + if (statp->options & INK_RES_DEBUG) { printf(";; res_setoptions(\"%s\", \"%s\")...\n", options, source); + } #endif while (*cp) { /* skip leading and inner runs of spaces */ @@ -185,8 +186,9 @@ ink_res_setoptions(ink_res_state statp, const char *options, const char *source statp->ndots = INK_RES_MAXNDOTS; } #ifdef DEBUG - if (statp->options & INK_RES_DEBUG) + if (statp->options & INK_RES_DEBUG) { printf(";;\tndots=%d\n", statp->ndots); + } #endif } else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) { i = atoi(cp + sizeof("timeout:") - 1); @@ -196,8 +198,9 @@ ink_res_setoptions(ink_res_state statp, const char *options, const char *source statp->retrans = INK_RES_MAXRETRANS; } #ifdef DEBUG - if (statp->options & INK_RES_DEBUG) + if (statp->options & INK_RES_DEBUG) { printf(";;\ttimeout=%d\n", statp->retrans); + } #endif #ifdef SOLARIS2 } else if (!strncmp(cp, "retrans:", sizeof("retrans:") - 1)) { @@ -223,8 +226,9 @@ ink_res_setoptions(ink_res_state statp, const char *options, const char *source statp->retry = INK_RES_MAXRETRY; } #ifdef DEBUG - if (statp->options & INK_RES_DEBUG) + if (statp->options & INK_RES_DEBUG) { printf(";;\tattempts=%d\n", statp->retry); + } #endif } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { #ifdef DEBUG @@ -568,8 +572,9 @@ ink_res_init(ink_res_state statp, ///< State object to update. #ifdef DEBUG if (statp->options & INK_RES_DEBUG) { printf(";; res_init()... default dnsrch list:\n"); - for (pp = statp->dnsrch; *pp; pp++) + for (pp = statp->dnsrch; *pp; pp++) { printf(";;\t%s\n", *pp); + } printf(";;\t..END..\n"); } #endif diff --git a/src/tscore/ink_res_mkquery.cc b/src/tscore/ink_res_mkquery.cc index 85af97f..eaffd04 100644 --- a/src/tscore/ink_res_mkquery.cc +++ b/src/tscore/ink_res_mkquery.cc @@ -516,8 +516,7 @@ ats_host_res_from(int family, HostResPreferenceOrder const &order) bool v4 = false, v6 = false; HostResPreference client = AF_INET6 == family ? HOST_RES_PREFER_IPV6 : HOST_RES_PREFER_IPV4; - for (int i = 0; i < N_HOST_RES_PREFERENCE_ORDER; ++i) { - HostResPreference p = order[i]; + for (auto p : order) { if (HOST_RES_PREFER_CLIENT == p) { p = client; // CLIENT -> actual value } diff --git a/src/tscore/unit_tests/test_Regex.cc b/src/tscore/unit_tests/test_Regex.cc index b0ee29b..e457345 100644 --- a/src/tscore/unit_tests/test_Regex.cc +++ b/src/tscore/unit_tests/test_Regex.cc @@ -28,15 +28,15 @@ #include "tscore/Regex.h" #include "catch.hpp" -typedef struct { +struct subject_match_t { std::string_view subject; bool match; -} subject_match_t; +}; -typedef struct { +struct test_t { std::string_view regex; std::array<subject_match_t, 4> tests; -} test_t; +}; std::array<test_t, 2> test_data{{{{"^foo"}, {{{{"foo"}, true}, {{"bar"}, false}, {{"foobar"}, true}, {{"foobarbaz"}, true}}}}, {{"foo$"}, {{{{"foo"}, true}, {{"bar"}, false}, {{"foobar"}, false}, {{"foobarbaz"}, false}}}}}}; diff --git a/tools/jtest/jtest.cc b/tools/jtest/jtest.cc index eaaa402..3f04a50 100644 --- a/tools/jtest/jtest.cc +++ b/tools/jtest/jtest.cc @@ -446,7 +446,7 @@ FD::close() #define MAX_FILE_ARGUMENTS 100 -typedef struct { +struct InkWebURLComponents { char sche[MAX_URL_LEN + 1]; char host[MAX_URL_LEN + 1]; char port[MAX_URL_LEN + 1]; @@ -466,7 +466,7 @@ typedef struct { int rel_url; int leading_slash; int is_path_name; -} InkWebURLComponents; +}; static int ink_web_remove_dots(char *src, char *dest, int *leadingslash, int max_dest_len);