diff --git a/example/plugins/cpp-api/websocket/WSBuffer.cc b/example/plugins/cpp-api/websocket/WSBuffer.cc index 0bbd05dced0..3b8a9b39ada 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(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 e36eafd1693..80a83948124 100644 --- a/iocore/cache/Cache.cc +++ b/iocore/cache/Cache.cc @@ -2772,7 +2772,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(((double)(config_vol->percent / percent_remaining)) * tot_space_in_blks); + space_in_blks = static_cast(((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 f8ae328f581..d3055f4e881 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(c->buf->data()); memcpy(doc->data(), to, sizeof(*to)); // doublecheck #endif diff --git a/iocore/eventsystem/UnixEventProcessor.cc b/iocore/eventsystem/UnixEventProcessor.cc index c2f7fade8ba..c3a30fe494c 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(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 a3f24a42e8c..484ea456a88 100644 --- a/iocore/net/P_QUICNetVConnection.h +++ b/iocore/net/P_QUICNetVConnection.h @@ -308,7 +308,7 @@ class QUICNetVConnection : public UnixNetVConnection, QUICPacketUPtr _packetize_frames(uint8_t *packet_buf, QUICEncryptionLevel level, uint64_t max_packet_size, std::vector &frames); void _packetize_closing_frame(); - QUICPacketUPtr _build_packet(uint8_t *packet_buf, QUICEncryptionLevel level, Ptr parent_block, + QUICPacketUPtr _build_packet(uint8_t *packet_buf, QUICEncryptionLevel level, const Ptr &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 @@ class QUICNetVConnection : public UnixNetVConnection, 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 d7f6dc2212f..0eaae2242ae 100644 --- a/iocore/net/P_QUICPacketHandler.h +++ b/iocore/net/P_QUICPacketHandler.h @@ -42,7 +42,7 @@ class QUICPacketHandler ~QUICPacketHandler(); void send_packet(const QUICPacket &packet, QUICNetVConnection *vc, const QUICPacketHeaderProtector &pn_protector); - void send_packet(QUICNetVConnection *vc, Ptr udp_payload); + void send_packet(QUICNetVConnection *vc, const Ptr &udp_payload); void close_connection(QUICNetVConnection *conn); diff --git a/iocore/net/P_SSLUtils.h b/iocore/net/P_SSLUtils.h index 5f0e40250f2..46553dd28c2 100644 --- a/iocore/net/P_SSLUtils.h +++ b/iocore/net/P_SSLUtils.h @@ -85,12 +85,12 @@ class SSLMultiCertConfigLoader 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 &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 34e21ae2272..31d33d9ea96 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(e->con); - uint8_t *buf = (uint8_t *)p->getIOBlockChain()->buf(); + uint8_t *buf = reinterpret_cast(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(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(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 6af1fd6d267..f78186e9f49 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(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 parent_block, +QUICNetVConnection::_build_packet(uint8_t *packet_buf, QUICEncryptionLevel level, const Ptr &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 a6e214d2b5f..7c9135130a6 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 *queue = (Queue *)data; + Queue *queue = static_cast *>(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((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 udp_payload) +QUICPacketHandler::send_packet(QUICNetVConnection *vc, const Ptr &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 *queue = (Queue *)data; + Queue *queue = reinterpret_cast *>(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 b3f5424798e..b3ee80686c9 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 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 &names) { bool inserted = false; diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc index a0e860b5872..c1c608b9836 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 34e498aa778..07eeef8b1f0 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/icap/icap_plugin.cc b/plugins/experimental/icap/icap_plugin.cc index b00450e8b44..38ab73dd79f 100644 --- a/plugins/experimental/icap/icap_plugin.cc +++ b/plugins/experimental/icap/icap_plugin.cc @@ -215,8 +215,8 @@ handle_invalid_icap_behavior(TSCont contp, TransformData *data, const char *msg) { if (data->icap_vc) { TSVConnAbort(data->icap_vc, 1); - data->icap_vc = NULL; - data->icap_vio = NULL; + data->icap_vc = nullptr; + data->icap_vio = nullptr; } TSStatIntIncrement(total_icap_invalid, 1); TSDebug(PLUGIN_NAME, "\n%s\n", data->icap_header.c_str()); @@ -256,8 +256,9 @@ handle_invalid_icap_behavior(TSCont contp, TransformData *data, const char *msg) static int handle_icap_headers(TSCont contp, TransformData *data) { - int64_t pos = data->icap_header.find("\r\n"); - std::string icap_status_line = pos != (int64_t)std::string::npos ? data->icap_header.substr(0, pos) : data->icap_header; + int64_t pos = data->icap_header.find("\r\n"); + std::string icap_status_line = + pos != static_cast(std::string::npos) ? data->icap_header.substr(0, pos) : data->icap_header; /* Check icap header to determine whether the scan passed or not */ if (data->icap_header.find("X-Infection-Found") != std::string::npos || data->icap_header.find("X-Violations-Found") != std::string::npos) { @@ -286,14 +287,15 @@ static void handle_icap_http_header(TransformData *data) { // TSDebug(PLUGIN_NAME, "Handling http header"); - int64_t pos = data->http_header.find("\r\n"); - std::string http_status_line = pos != (int64_t)std::string::npos ? data->http_header.substr(0, pos) : data->http_header; + int64_t pos = data->http_header.find("\r\n"); + std::string http_status_line = + pos != static_cast(std::string::npos) ? data->http_header.substr(0, pos) : data->http_header; /* find content length from header if any */ std::smatch sm; std::regex e("(Content-Length: )([[:digit:]]+)"); regex_search(data->http_header, sm, e); if (sm.size()) { - data->icap_reply_content_length = std::stoll(sm[2].str().c_str(), NULL, 10); + data->icap_reply_content_length = std::stoll(sm[2].str().c_str(), nullptr, 10); } /* Replace header with the returned header from icap server */ TSMBuffer bufp; @@ -357,7 +359,7 @@ handle_read_http_body(TSCont contp, TransformData *data) int64_t pos = sm.position(0); int64_t token_length = sm[0].length(); - data->http_body_chunk_length = std::stoi(sm[2].str().c_str(), NULL, 16); + data->http_body_chunk_length = std::stoi(sm[2].str().c_str(), nullptr, 16); data->http_body_total_length_written += data->http_body_chunk_length; TSIOBufferReaderConsume(data->icap_resp_reader, pos + token_length - consumed); break; @@ -367,8 +369,9 @@ handle_read_http_body(TSCont contp, TransformData *data) consumed += data_len; blk = TSIOBufferBlockNext(blk); } - if (blk == nullptr) + if (blk == nullptr) { return 0; + } } /* Write the chunk to downstream */ @@ -388,12 +391,12 @@ handle_read_http_body(TSCont contp, TransformData *data) /* If no more data is to be read for now. Check for eos to determine whether data is incomplete. */ if (data->eos_detected) { TSVConnAbort(data->icap_vc, 1); - data->icap_vc = NULL; - data->icap_vio = NULL; + data->icap_vc = nullptr; + data->icap_vio = nullptr; TSVConnAbort(data->output_vc, 1); - data->output_vc = NULL; - data->output_vio = NULL; + data->output_vc = nullptr; + data->output_vio = nullptr; return 0; } } @@ -420,12 +423,13 @@ transform_destroy(TSCont contp) { TransformData *data; - data = (TransformData *)TSContDataGet(contp); + data = static_cast(TSContDataGet(contp)); - if (data != NULL) + if (data != nullptr) { delete data; - else + } else { TSError("[%s] Unable to get Continuation's Data. TSContDataGet returns NULL", PLUGIN_NAME); + } TSContDestroy(contp); } @@ -449,7 +453,7 @@ transform_connect(TSCont contp, TransformData *data) TSError("[%s] Invalid address: %s", PLUGIN_NAME, server_ip.c_str()); return 0; } - action = TSNetConnect(contp, (struct sockaddr const *)&ip_addr); + action = TSNetConnect(contp, reinterpret_cast(&ip_addr)); if (!TSActionDone(action)) { data->pending_action = action; @@ -478,7 +482,7 @@ transform_read_icap_header(TSCont contp, TransformData *data) data->icap_resp_buf = TSIOBufferCreate(); data->icap_resp_reader = TSIOBufferReaderAlloc(data->icap_resp_buf); - if (data->icap_resp_reader != NULL) { + if (data->icap_resp_reader != nullptr) { data->icap_vio = TSVConnRead(data->icap_vc, contp, data->icap_resp_buf, INT64_MAX); } else { TSError("[%s] Error in Allocating a Reader to output buffer. TSIOBufferReaderAlloc returns NULL", PLUGIN_NAME); @@ -493,7 +497,7 @@ transform_read_http_header(TSCont contp, TransformData *data) data->state = State::READ_HTTP_HEADER; if (TSIOBufferReaderAvail(data->icap_resp_reader)) { - transform_read_http_header_event(contp, data, TS_EVENT_VCONN_READ_READY, NULL); + transform_read_http_header_event(contp, data, TS_EVENT_VCONN_READ_READY, nullptr); } return 0; @@ -506,7 +510,7 @@ transform_read_http_body(TSCont contp, TransformData *data) data->output_buf = TSIOBufferCreate(); data->output_reader = TSIOBufferReaderAlloc(data->output_buf); - data->output_vc = TSTransformOutputVConnGet((TSVConn)contp); + data->output_vc = TSTransformOutputVConnGet(static_cast(contp)); // data->output_vio = TSVConnWrite(data->output_vc, contp, data->output_reader, INT64_MAX); if (data->icap_reply_content_length) { data->output_vio = TSVConnWrite(data->output_vc, contp, data->output_reader, data->icap_reply_content_length); @@ -656,15 +660,15 @@ transform_send_error_msg(TSCont contp, TransformData *data) data->state = State::SEND_ERROR_MSG; data->output_buf = TSIOBufferCreate(); data->output_reader = TSIOBufferReaderAlloc(data->output_buf); - data->output_vc = TSTransformOutputVConnGet((TSVConn)contp); + data->output_vc = TSTransformOutputVConnGet(static_cast(contp)); TSIOBufferWrite(data->output_buf, data->err_msg.c_str(), data->err_msg.size()); - if (data->output_vc == NULL) { + if (data->output_vc == nullptr) { TSError("[%s] TSTransformOutputVConnGet returns NULL", PLUGIN_NAME); } else { data->output_vio = TSVConnWrite(data->output_vc, contp, data->output_reader, TSIOBufferReaderAvail(data->output_reader)); - if (data->output_vio == NULL) { + if (data->output_vio == nullptr) { TSError("[%s] TSVConnWrite returns NULL", PLUGIN_NAME); } } @@ -682,13 +686,13 @@ transform_bypass(TSCont contp, TransformData *data) data->state = State::BYPASS; data->output_buf = TSIOBufferCreate(); data->output_reader = TSIOBufferReaderAlloc(data->output_buf); - data->output_vc = TSTransformOutputVConnGet((TSVConn)contp); + data->output_vc = TSTransformOutputVConnGet(static_cast(contp)); - if (data->output_vc == NULL) { + if (data->output_vc == nullptr) { TSError("[%s] TSTransformOutputVConnGet returns NULL", PLUGIN_NAME); } else { data->output_vio = TSVConnWrite(data->output_vc, contp, data->output_reader, 0); - if (data->output_vio == NULL) { + if (data->output_vio == nullptr) { TSError("[%s] TSVConnWrite returns NULL", PLUGIN_NAME); } } @@ -727,13 +731,13 @@ transform_send_os_resp(TSCont contp, TransformData *data) data->state = State::SEND_OS_RESP; data->output_buf = TSIOBufferCreate(); data->output_reader = TSIOBufferReaderAlloc(data->output_buf); - data->output_vc = TSTransformOutputVConnGet((TSVConn)contp); + data->output_vc = TSTransformOutputVConnGet(static_cast(contp)); - if (data->output_vc == NULL) { + if (data->output_vc == nullptr) { TSError("[%s] TSTransformOutputVConnGet returns NULL", PLUGIN_NAME); } else { data->output_vio = TSVConnWrite(data->output_vc, contp, data->os_resp_reader, TSIOBufferReaderAvail(data->os_resp_reader)); - if (data->output_vio == NULL) { + if (data->output_vio == nullptr) { TSError("[%s] TSVConnWrite returns NULL", PLUGIN_NAME); } } @@ -746,12 +750,12 @@ transform_connect_event(TSCont contp, TransformData *data, TSEvent event, void * { switch (event) { case TS_EVENT_NET_CONNECT: - data->pending_action = NULL; - data->icap_vc = (TSVConn)edata; + data->pending_action = nullptr; + data->icap_vc = static_cast(edata); return handle_write_header(contp, data); case TS_EVENT_NET_CONNECT_FAILED: TSStatIntIncrement(icap_conn_failed, 1); - data->pending_action = NULL; + data->pending_action = nullptr; return handle_invalid_icap_behavior(contp, data, "Cannot connect to ICAP scanner."); default: break; @@ -821,7 +825,7 @@ transform_read_icap_header_event(TSCont contp, TransformData *data, TSEvent even while (read_nbytes > 0) { TSIOBufferBlock blk = TSIOBufferReaderStart(reader); - char *buf = (char *)TSIOBufferBlockReadStart(blk, reader, &avail); + char *buf = const_cast(TSIOBufferBlockReadStart(blk, reader, &avail)); int64_t read_ndone = (avail >= read_nbytes) ? read_nbytes : avail; int64_t consume = read_ndone; std::string chunk = std::string(buf, read_ndone); @@ -832,22 +836,24 @@ transform_read_icap_header_event(TSCont contp, TransformData *data, TSEvent even int64_t pos = data->icap_header.find("\r\n\r\n"); int64_t token_length = std::string("\r\n\r\n").size(); - if (pos != (int64_t)std::string::npos) { + if (pos != static_cast(std::string::npos)) { data->icap_header.resize(pos); consume = pos + token_length - consumed; TSIOBufferReaderConsume(reader, consume); - if (handle_icap_headers(contp, data)) + if (handle_icap_headers(contp, data)) { return transform_send_os_resp(contp, data); - else + } else { return transform_read_http_header(contp, data); + } } if (read_ndone > 0) { read_nbytes -= consume; TSIOBufferReaderConsume(reader, consume); consumed += consume; - } else + } else { break; + } } break; } @@ -876,7 +882,7 @@ transform_read_http_header_event(TSCont contp, TransformData *data, TSEvent even while (read_nbytes > 0) { TSIOBufferBlock blk = TSIOBufferReaderStart(reader); - char *buf = (char *)TSIOBufferBlockReadStart(blk, reader, &avail); + char *buf = const_cast(TSIOBufferBlockReadStart(blk, reader, &avail)); int64_t read_ndone = (avail >= read_nbytes) ? read_nbytes : avail; int64_t consume = read_ndone; std::string chunk = std::string(buf, read_ndone); @@ -886,7 +892,7 @@ transform_read_http_header_event(TSCont contp, TransformData *data, TSEvent even int64_t pos = data->http_header.find("\r\n\r\n"); int64_t token_length = std::string("\r\n").size(); - if (pos != (int64_t)std::string::npos) { + if (pos != static_cast(std::string::npos)) { data->http_header.resize(pos); consume = pos + token_length - consumed; TSIOBufferReaderConsume(reader, consume); @@ -898,8 +904,9 @@ transform_read_http_header_event(TSCont contp, TransformData *data, TSEvent even read_nbytes -= consume; TSIOBufferReaderConsume(reader, consume); consumed += consume; - } else + } else { break; + } } if (read_nbytes <= 0) { @@ -920,12 +927,12 @@ transform_read_http_body_event(TSCont contp, TransformData *data, TSEvent event, switch (event) { case TS_EVENT_ERROR: TSVConnAbort(data->icap_vc, 1); - data->icap_vc = NULL; - data->icap_vio = NULL; + data->icap_vc = nullptr; + data->icap_vio = nullptr; TSVConnAbort(data->output_vc, 1); - data->output_vc = NULL; - data->output_vio = NULL; + data->output_vc = nullptr; + data->output_vio = nullptr; break; case TS_EVENT_VCONN_EOS: TSVConnShutdown(data->icap_vc, 1, 0); @@ -1061,8 +1068,8 @@ transform_handler(TSCont contp, TSEvent event, void *edata) } else { TransformData *data; - data = (TransformData *)TSContDataGet(contp); - if (data == NULL) { + data = static_cast(TSContDataGet(contp)); + if (data == nullptr) { TSError("[%s] Didn't get Continuation's Data, ignoring event", PLUGIN_NAME); return 0; } @@ -1159,7 +1166,7 @@ server_response_ok(TSHttpTxn txnp) static int transform_plugin(TSCont contp, TSEvent event, void *edata) { - TSHttpTxn txnp = (TSHttpTxn)edata; + TSHttpTxn txnp = static_cast(edata); switch (event) { case TS_EVENT_HTTP_READ_REQUEST_HDR: @@ -1235,6 +1242,6 @@ TSPluginInit(int argc, const char *argv[]) TSStatIntSet(icap_response_err, 0); TSStatIntSet(total_icap_invalid, 0); - cont = TSContCreate(transform_plugin, NULL); + cont = TSContCreate(transform_plugin, nullptr); TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont); } diff --git a/plugins/experimental/maxmind_acl/mmdb.cc b/plugins/experimental/maxmind_acl/mmdb.cc index 1634fe8412a..bc764a5d15c 100644 --- a/plugins/experimental/maxmind_acl/mmdb.cc +++ b/plugins/experimental/maxmind_acl/mmdb.cc @@ -117,7 +117,7 @@ Acl::init(char const *filename) /////////////////////////////////////////////////////////////////////////////// // Parse the deny list country codes and IPs bool -Acl::loaddeny(YAML::Node denyNode) +Acl::loaddeny(const YAML::Node &denyNode) { if (!denyNode) { TSDebug(PLUGIN_NAME, "No Deny rules set"); @@ -197,7 +197,7 @@ Acl::loaddeny(YAML::Node denyNode) // Parse the allow list country codes and IPs bool -Acl::loadallow(YAML::Node allowNode) +Acl::loadallow(const YAML::Node &allowNode) { if (!allowNode) { TSDebug(PLUGIN_NAME, "No Allow rules set"); @@ -277,7 +277,7 @@ Acl::loadallow(YAML::Node allowNode) } void -Acl::parseregex(YAML::Node regex, bool allow) +Acl::parseregex(const YAML::Node ®ex, bool allow) { try { if (!regex.IsNull()) { @@ -321,7 +321,7 @@ Acl::parseregex(YAML::Node regex, bool allow) } void -Acl::loadhtml(YAML::Node htmlNode) +Acl::loadhtml(const YAML::Node &htmlNode) { std::string htmlname, htmlloc; std::ifstream f; @@ -357,7 +357,7 @@ Acl::loadhtml(YAML::Node htmlNode) /////////////////////////////////////////////////////////////////////////////// // Load the maxmind database from the config parameter bool -Acl::loaddb(YAML::Node dbNode) +Acl::loaddb(const YAML::Node &dbNode) { std::string dbloc, dbname; @@ -490,7 +490,7 @@ Acl::eval_country(MMDB_entry_data_s *entry_data, const char *path, int path_len) { bool ret = false; bool allow = default_allow; - char *output = NULL; + char *output = nullptr; output = (char *)malloc((sizeof(char) * entry_data->data_size)); strncpy(output, entry_data->utf8_string, entry_data->data_size); TSDebug(PLUGIN_NAME, "This IP Country Code: %s", output); diff --git a/plugins/experimental/maxmind_acl/mmdb.h b/plugins/experimental/maxmind_acl/mmdb.h index aa73c3bb244..93a1cac9883 100644 --- a/plugins/experimental/maxmind_acl/mmdb.h +++ b/plugins/experimental/maxmind_acl/mmdb.h @@ -98,11 +98,11 @@ class Acl bool default_allow = false; bool db_loaded = false; - bool loaddb(YAML::Node dbNode); - bool loadallow(YAML::Node allowNode); - bool loaddeny(YAML::Node denyNode); - void loadhtml(YAML::Node htmlNode); + bool loaddb(const YAML::Node &dbNode); + bool loadallow(const YAML::Node &allowNode); + bool loaddeny(const YAML::Node &denyNode); + void loadhtml(const YAML::Node &htmlNode); bool eval_country(MMDB_entry_data_s *entry_data, const char *path, int path_len); - void parseregex(YAML::Node regex, bool allow); + void parseregex(const YAML::Node regex, bool allow); ipstate eval_ip(const sockaddr *sock) const; }; diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc index 8e405d3ae9c..532c2bb4b31 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/memory_profile/memory_profile.cc b/plugins/experimental/memory_profile/memory_profile.cc index 85a4c707f6c..163f3dd9656 100644 --- a/plugins/experimental/memory_profile/memory_profile.cc +++ b/plugins/experimental/memory_profile/memory_profile.cc @@ -26,12 +26,12 @@ * System must be built with jemalloc to be useful */ -#include +#include #include -#include +#include #include -#include -#include +#include +#include #include #if TS_HAS_JEMALLOC #include @@ -45,7 +45,7 @@ CallbackHandler(TSCont cont, TSEvent id, void *data) (void)cont; // make compiler shut up about unused variable. if (id == TS_EVENT_LIFECYCLE_MSG) { - TSPluginMsg *msg = (TSPluginMsg *)data; + TSPluginMsg *msg = static_cast(data); TSDebug(PLUGIN_NAME, "Message to '%s' - %zu bytes of data", msg->tag, msg->data_size); if (strcmp(PLUGIN_NAME, msg->tag) == 0) { // Message is for us #if TS_HAS_JEMALLOC @@ -96,7 +96,7 @@ TSPluginInit(int argc, const char *argv[]) goto Lerror; } - cb = TSContCreate(CallbackHandler, NULL); + cb = TSContCreate(CallbackHandler, nullptr); TSLifecycleHookAdd(TS_LIFECYCLE_MSG_HOOK, cb); diff --git a/plugins/experimental/metalink/metalink.cc b/plugins/experimental/metalink/metalink.cc index fc97e1489f7..9f7d201a410 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 31809bb33b8..727c752a42b 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(edata); config_t *config; void *txnd; diff --git a/plugins/experimental/slice/Config.cc b/plugins/experimental/slice/Config.cc index 2ff68662d6e..54df2f1428b 100644 --- a/plugins/experimental/slice/Config.cc +++ b/plugins/experimental/slice/Config.cc @@ -151,7 +151,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 { @@ -169,7 +169,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 { @@ -269,12 +269,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 c0dfb046d9b..c8c4fa3036b 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(0), (m_end - 1) / blocksize); } else { return -1; } diff --git a/plugins/experimental/slice/server.cc b/plugins/experimental/slice/server.cc index ac989c447a2..bdc37daf049 100644 --- a/plugins/experimental/slice/server.cc +++ b/plugins/experimental/slice/server.cc @@ -75,7 +75,7 @@ contentLengthFrom(HttpHeader const &header) // ensure null termination constr[conlen] = '\0'; char *endptr = nullptr; - bytes = std::max((int64_t)0, (int64_t)strtoll(constr, &endptr, 10)); + bytes = std::max(static_cast(0), static_cast(strtoll(constr, &endptr, 10))); } return bytes; diff --git a/plugins/experimental/slice/slice.cc b/plugins/experimental/slice/slice.cc index ff33650fbe5..dcb63b8595c 100644 --- a/plugins/experimental/slice/slice.cc +++ b/plugins/experimental/slice/slice.cc @@ -46,7 +46,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(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 80f0868de7f..04516d4c12a 100644 --- a/plugins/experimental/slice/util.cc +++ b/plugins/experimental/slice/util.cc @@ -86,7 +86,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(&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 6aabf26ba64..7c07a0ab192 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 +#include #include 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::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(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(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(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(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(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 e14cef8948f..a40b33c1ee9 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(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 7bcd2720312..0bd7d8a8839 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 e496c59981c..de41e09dc6a 100644 --- a/plugins/experimental/traffic_dump/session_data.cc +++ b/plugins/experimental/traffic_dump/session_data.cc @@ -152,7 +152,7 @@ using get_tls_description_f = std::function; * @return The description of the protocol stack. */ std::string -get_protocol_stack_helper(get_protocol_stack_f get_protocol_stack, get_tls_description_f get_tls_node) +get_protocol_stack_helper(const get_protocol_stack_f &get_protocol_stack, const get_tls_description_f &get_tls_node) { std::ostringstream protocol_description; protocol_description << R"("protocol":[)"; @@ -399,7 +399,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_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 20c5f126512..51f63507db4 100644 --- a/plugins/experimental/traffic_dump/transaction_data.cc +++ b/plugins/experimental/traffic_dump/transaction_data.cc @@ -280,7 +280,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 b5728e73e3e..0e7468f1c8f 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 1be2d54f120..9783e627725 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 ec946099d7f..3ef5b52c934 100644 --- a/proxy/ControlMatcher.cc +++ b/proxy/ControlMatcher.cc @@ -664,10 +664,10 @@ void IpMatcher::Print() const { 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(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(spot.data())->Print(); } } diff --git a/proxy/ParentConsistentHash.cc b/proxy/ParentConsistentHash.cc index f7977d75fd1..568fba97d92 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 b9a43727d69..e0fb43c321a 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(field->m_next_dup); + if ((addr >= reinterpret_cast(blk)) && + (addr < reinterpret_cast(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 5d07691e182..d2f8b2c3ad0 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 4951fe08464..c14c971bf9a 100644 --- a/proxy/http/remap/NextHopConsistentHash.cc +++ b/proxy/http/remap/NextHopConsistentHash.cc @@ -36,7 +36,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 ring, uint64_t hash_key, ATSConsistentHashIter *iter, bool *wrapped, +chash_lookup(const std::shared_ptr &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/NextHopHealthStatus.cc b/proxy/http/remap/NextHopHealthStatus.cc index 4ae65800fa9..afb43c7222c 100644 --- a/proxy/http/remap/NextHopHealthStatus.cc +++ b/proxy/http/remap/NextHopHealthStatus.cc @@ -30,8 +30,7 @@ void NextHopHealthStatus::insert(std::vector> &hosts) { - for (uint32_t ii = 0; ii < hosts.size(); ii++) { - std::shared_ptr h = hosts[ii]; + for (auto h : hosts) { for (auto protocol = h->protocols.begin(); protocol != h->protocols.end(); ++protocol) { const std::string host_port = h->getHostPort((*protocol)->port); host_map.emplace(std::make_pair(host_port, h)); diff --git a/proxy/http/remap/NextHopSelectionStrategy.cc b/proxy/http/remap/NextHopSelectionStrategy.cc index 0b0f76638fa..e589c3ebc2f 100644 --- a/proxy/http/remap/NextHopSelectionStrategy.cc +++ b/proxy/http/remap/NextHopSelectionStrategy.cc @@ -108,8 +108,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(); + for (auto &&k : resp_codes_node) { + auto code = k.as(); if (code > 300 && code < 599) { resp_codes.add(code); } else { @@ -208,8 +208,8 @@ NextHopSelectionStrategy::nextHopExists(TSHttpTxn txnp, void *ih) int64_t sm_id = sm->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; @@ -262,9 +262,9 @@ template <> struct convert { 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 pr = std::make_shared(protocol_node.as()); + for (auto &&ii : proto) { + const YAML::Node &protocol_node = ii; + std::shared_ptr pr = std::make_shared(protocol_node.as()); nh.protocols.push_back(std::move(pr)); } } diff --git a/proxy/http/remap/NextHopStrategyFactory.cc b/proxy/http/remap/NextHopStrategyFactory.cc index 1bfc9ec04ef..4de0b8aa521 100644 --- a/proxy/http/remap/NextHopStrategyFactory.cc +++ b/proxy/http/remap/NextHopStrategyFactory.cc @@ -24,7 +24,7 @@ #include #include -#include +#include #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(); 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 &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 3ef5cdc9e3d..ecb25a8943c 100644 --- a/proxy/http/remap/NextHopStrategyFactory.h +++ b/proxy/http/remap/NextHopStrategyFactory.h @@ -48,7 +48,7 @@ class NextHopStrategyFactory private: std::string fn; - void loadConfigFile(const std::string file, std::stringstream &doc, std::unordered_set &include_once); + void loadConfigFile(const std::string &file, std::stringstream &doc, std::unordered_set &include_once); void createStrategy(const std::string &name, const NHPolicyType policy_type, const YAML::Node &node); std::unordered_map> _strategies; }; diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc index 33da376d053..fe4afa38d7e 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(&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 6aeae95b6bc..a394c0818fa 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(real_len) < padded_len) { dest[real_len] = '$'; real_len++; } diff --git a/proxy/logging/LogFile.cc b/proxy/logging/LogFile.cc index 26fcca6467d..89bdc808d59 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(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(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 53be58e4b5a..c581e1f223a 100644 --- a/src/traffic_logstats/logstats.cc +++ b/src/traffic_logstats/logstats.cc @@ -336,10 +336,10 @@ struct hash_fnv32 { } }; -using LruStack = std::list; -typedef std::unordered_map OriginStorage; -typedef std::unordered_set OriginSet; -typedef std::unordered_map LruHash; +using LruStack = std::list; +using OriginStorage = std::unordered_map; +using OriginSet = std::unordered_set; +using LruHash = std::unordered_map; // Resize a hash-based container. template @@ -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 OriginPair; +using OriginPair = pair; inline bool operator<(const OriginPair &a, const OriginPair &b) { diff --git a/src/traffic_server/FetchSM.cc b/src/traffic_server/FetchSM.cc index 0cb2919537c..aa735978475 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 1b0bad1df09..2b137453b92 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 5ba9bc3c614..9d1dff707eb 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(-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(-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(-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(-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(-1)); } return htonl((u[0] << 24) | (u[1] << 16) | (u[2] << 8) | u[3]); } - return htonl((uint32_t)-1); + return htonl(static_cast(-1)); } const char * diff --git a/src/tscore/ink_queue.cc b/src/tscore/ink_queue.cc index 22f3b32382e..f4a2841c06f 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(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(0xde), static_cast(0xad), static_cast(0xbe), static_cast(0xef)}; + for (int j = 0; j < static_cast(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(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(0xde), static_cast(0xad), static_cast(0xbe), static_cast(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(f->type_size); j++) { + (static_cast(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(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(0xde), static_cast(0xad), static_cast(0xbe), static_cast(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(f->type_size); j++) { + (static_cast(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(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 42638a8c170..fdc34bf73ba 100644 --- a/src/tscore/ink_res_init.cc +++ b/src/tscore/ink_res_init.cc @@ -169,8 +169,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 */ @@ -186,8 +187,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); @@ -197,8 +199,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)) { @@ -224,8 +227,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 @@ -569,8 +573,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/unit_tests/test_Regex.cc b/src/tscore/unit_tests/test_Regex.cc index b0ee29b9067..e457345fd85 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 tests; -} test_t; +}; std::array test_data{{{{"^foo"}, {{{{"foo"}, true}, {{"bar"}, false}, {{"foobar"}, true}, {{"foobarbaz"}, true}}}}, {{"foo$"}, {{{{"foo"}, true}, {{"bar"}, false}, {{"foobar"}, false}, {{"foobarbaz"}, false}}}}}}; diff --git a/tests/gold_tests/chunked_encoding/smuggle-client.c b/tests/gold_tests/chunked_encoding/smuggle-client.c index 928db415b10..db1101140fc 100644 --- a/tests/gold_tests/chunked_encoding/smuggle-client.c +++ b/tests/gold_tests/chunked_encoding/smuggle-client.c @@ -85,10 +85,12 @@ main(int argc, char *argv[]) for (rp = result; rp != NULL; rp = rp->ai_next) { sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (sfd == -1) + if (sfd == -1) { continue; - if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) + } + if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) { break; /* Success */ + } close(sfd); } diff --git a/tests/gold_tests/timeout/ssl-delay-server.cc b/tests/gold_tests/timeout/ssl-delay-server.cc index 0c0750c9992..8f121135664 100644 --- a/tests/gold_tests/timeout/ssl-delay-server.cc +++ b/tests/gold_tests/timeout/ssl-delay-server.cc @@ -25,10 +25,10 @@ #include #include #include -#include -#include +#include +#include #include -#include +#include #include #include #include @@ -38,7 +38,7 @@ #include #include #include -#include +#include char req_buf[10000]; char post_buf[1000]; @@ -47,7 +47,7 @@ SSL_CTX *svr_ctx; int connect_delay; int ttfb_delay; -pthread_mutex_t *mutex_buf = NULL; +pthread_mutex_t *mutex_buf = nullptr; struct thread_info { struct addrinfo *result, *rp; @@ -80,7 +80,7 @@ run_session(void *arg) { int sfd = (intptr_t)arg; SSL *ssl = SSL_new(svr_ctx); - if (ssl == NULL) { + if (ssl == nullptr) { fprintf(stderr, "Failed to create ssl\n"); return nullptr; } @@ -138,7 +138,7 @@ run_session(void *arg) } close(sfd); - return NULL; + return nullptr; } /** @@ -169,14 +169,14 @@ main(int argc, char *argv[]) serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(listen_port); - bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + bind(listenfd, reinterpret_cast(&serv_addr), sizeof(serv_addr)); SSL_load_error_strings(); SSL_library_init(); - mutex_buf = (pthread_mutex_t *)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); + mutex_buf = static_cast(OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t))); for (int i = 0; i < CRYPTO_num_locks(); i++) { - pthread_mutex_init(&mutex_buf[i], NULL); + pthread_mutex_init(&mutex_buf[i], nullptr); } CRYPTO_set_locking_callback(SSL_locking_callback); @@ -199,7 +199,7 @@ main(int argc, char *argv[]) listen(listenfd, 10); for (;;) { - sfd = accept(listenfd, (struct sockaddr *)NULL, NULL); + sfd = accept(listenfd, (struct sockaddr *)nullptr, nullptr); if (sfd <= 0) { // Failure printf("Listen failure\n"); @@ -210,7 +210,7 @@ main(int argc, char *argv[]) // Spawn off new thread pthread_t thread_id; - pthread_create(&thread_id, NULL, run_session, (void *)((intptr_t)sfd)); + pthread_create(&thread_id, nullptr, run_session, (void *)(static_cast(sfd))); } exit(0); diff --git a/tests/gold_tests/tls/ssl-post.c b/tests/gold_tests/tls/ssl-post.c index 58376fdb6cf..eeb80378453 100644 --- a/tests/gold_tests/tls/ssl-post.c +++ b/tests/gold_tests/tls/ssl-post.c @@ -142,8 +142,9 @@ spawn_same_session_send(void *arg) ret = select(sfd + 1, &reads, &writes, NULL, NULL); if (FD_ISSET(sfd, &reads) || FD_ISSET(sfd, &writes)) { ret = write_ret = SSL_write(ssl, req_buf, strlen(req_buf)); - if (write_ret > 0) + if (write_ret > 0) { post_write_ret = SSL_write(ssl, post_buf, sizeof(post_buf)); + } } } @@ -198,10 +199,11 @@ spawn_same_session_send(void *arg) read_bytes = SSL_read(ssl, input_buf, sizeof(input_buf)); } } - if (read_bytes > 0 && read_bytes < 1024) + if (read_bytes > 0 && read_bytes < 1024) { input_buf[read_bytes] = '\0'; - else + } else { input_buf[1023] = '\0'; + } // printf("total_bytes=%d Received bytes=%d handshake writes=%d handshake reads=%d\n", total_read, read_bytes, write_count, // read_count); @@ -264,10 +266,12 @@ main(int argc, char *argv[]) for (rp = result; rp != NULL; rp = rp->ai_next) { sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (sfd == -1) + if (sfd == -1) { continue; - if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) + } + if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) { break; /* Success */ + } close(sfd); } @@ -320,10 +324,11 @@ main(int argc, char *argv[]) char input_buf[1024]; int read_bytes = SSL_read(ssl, input_buf, sizeof(input_buf)); - if (read_bytes > 0 && read_bytes < 1024) + if (read_bytes > 0 && read_bytes < 1024) { input_buf[read_bytes] = '\0'; - else + } else { input_buf[1023] = '\0'; + } // printf("Received %d bytes %s\n", read_bytes, input_buf); SSL_SESSION *session = SSL_get_session(ssl); close(sfd); diff --git a/tests/tools/plugins/cert_update.cc b/tests/tools/plugins/cert_update.cc index 1bb18eb43ce..53eeacd0d17 100644 --- a/tests/tools/plugins/cert_update.cc +++ b/tests/tools/plugins/cert_update.cc @@ -21,7 +21,7 @@ limitations under the License. */ -#include +#include #include #include #include diff --git a/tests/tools/plugins/cont_schedule.cc b/tests/tools/plugins/cont_schedule.cc index 493c68d4e05..7706d895564 100644 --- a/tests/tools/plugins/cont_schedule.cc +++ b/tests/tools/plugins/cont_schedule.cc @@ -17,8 +17,8 @@ */ #include -#include // for abort -#include // for debug +#include // for abort +#include // for debug // debug messages viewable by setting 'proxy.config.diags.debug.tags' // in 'records.config' diff --git a/tests/tools/plugins/continuations_verify.cc b/tests/tools/plugins/continuations_verify.cc index 6ad633e5a6d..5e6525d9c7f 100644 --- a/tests/tools/plugins/continuations_verify.cc +++ b/tests/tools/plugins/continuations_verify.cc @@ -23,8 +23,8 @@ limitations under the License. */ -#include // for abort -#include // for debug +#include // for abort +#include // for debug // debug messages viewable by setting 'proxy.config.diags.debug.tags' // in 'records.config' diff --git a/tests/tools/plugins/custom204plugin.cc b/tests/tools/plugins/custom204plugin.cc index c925bb5c1a6..461bc08e261 100644 --- a/tests/tools/plugins/custom204plugin.cc +++ b/tests/tools/plugins/custom204plugin.cc @@ -22,7 +22,7 @@ */ #include "ts/ts.h" -#include "string.h" +#include #define PLUGIN_NAME "custom204plugintest" @@ -42,7 +42,7 @@ local_handler(TSCont contp, TSEvent event, void *edata) "This response was sent via the custom204plugin via a call to TSHttpTxnErrorBodySet.\n" "
\n" ""; - TSHttpTxn txnp = (TSHttpTxn)edata; + TSHttpTxn txnp = static_cast(edata); TSMBuffer bufp = nullptr; TSMLoc hdr_loc = nullptr; TSMLoc url_loc = nullptr; @@ -116,7 +116,7 @@ local_handler(TSCont contp, TSEvent event, void *edata) static int global_handler(TSCont contp, TSEvent event, void *edata) { - TSHttpTxn txnp = (TSHttpTxn)edata; + TSHttpTxn txnp = static_cast(edata); TSCont txn_contp = nullptr; switch (event) { diff --git a/tests/tools/plugins/emergency_shutdown.cc b/tests/tools/plugins/emergency_shutdown.cc index 9957e40e604..993d89d7ae6 100644 --- a/tests/tools/plugins/emergency_shutdown.cc +++ b/tests/tools/plugins/emergency_shutdown.cc @@ -17,8 +17,8 @@ */ #include -#include // for abort -#include // for debug +#include // for abort +#include // for debug // debug messages viewable by setting 'proxy.config.diags.debug.tags' // in 'records.config' diff --git a/tests/tools/plugins/fatal_shutdown.cc b/tests/tools/plugins/fatal_shutdown.cc index d749008ce53..65eec2b1da5 100644 --- a/tests/tools/plugins/fatal_shutdown.cc +++ b/tests/tools/plugins/fatal_shutdown.cc @@ -17,8 +17,8 @@ */ #include -#include // for abort -#include // for debug +#include // for abort +#include // for debug // debug messages viewable by setting 'proxy.config.diags.debug.tags' // in 'records.config' diff --git a/tests/tools/plugins/hook_add_plugin.cc b/tests/tools/plugins/hook_add_plugin.cc index adc9504139d..baf15e53f3d 100644 --- a/tests/tools/plugins/hook_add_plugin.cc +++ b/tests/tools/plugins/hook_add_plugin.cc @@ -57,7 +57,7 @@ transactionHandler(TSCont continuation, TSEvent event, void *d) int sessionHandler(TSCont continuation, TSEvent event, void *d) { - TSHttpTxn txnp = (TSHttpTxn)d; + TSHttpTxn txnp = static_cast(d); TSCont txn_contp; switch (event) { diff --git a/tests/tools/plugins/ssl_client_verify_test.cc b/tests/tools/plugins/ssl_client_verify_test.cc index c9de34bc587..e48dae8971f 100644 --- a/tests/tools/plugins/ssl_client_verify_test.cc +++ b/tests/tools/plugins/ssl_client_verify_test.cc @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -41,7 +41,7 @@ std::map good_names; bool -check_name(std::string name) +check_name(const std::string &name) { auto entry = good_names.find(name); return entry != good_names.end(); @@ -75,7 +75,7 @@ check_names(X509 *cert) } if (!retval) { // Check the subjectAltNanes (if present) - GENERAL_NAMES *names = (GENERAL_NAMES *)X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, nullptr); + GENERAL_NAMES *names = static_cast(X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, nullptr)); if (names) { unsigned count = sk_GENERAL_NAME_num(names); for (unsigned i = 0; i < count && !retval; ++i) { @@ -167,7 +167,7 @@ setup_callbacks(int count) TSDebug(PN, "Setup callbacks count=%d", count); for (i = 0; i < count; i++) { cb = TSContCreate(&CB_client_verify, TSMutexCreate()); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); TSHttpHookAdd(TS_SSL_VERIFY_CLIENT_HOOK, cb); } return; diff --git a/tests/tools/plugins/ssl_hook_test.cc b/tests/tools/plugins/ssl_hook_test.cc index 97412cd8e20..20be7822b36 100644 --- a/tests/tools/plugins/ssl_hook_test.cc +++ b/tests/tools/plugins/ssl_hook_test.cc @@ -296,7 +296,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int client_hello_count, client_hello_count_immediate, sni_count, cert_count, cert_count_immediate, preaccept_count_delay); for (i = 0; i < preaccept_count; i++) { cb = TSContCreate(&CB_Pre_Accept, nullptr); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_VCONN_START_HOOK, cb); } else { @@ -305,7 +305,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int } for (i = 0; i < preaccept_count_delay; i++) { cb = TSContCreate(&CB_Pre_Accept_Delay, nullptr); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_VCONN_START_HOOK, cb); } else { @@ -314,7 +314,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int } for (i = 0; i < client_hello_count; i++) { cb = TSContCreate(&CB_Client_Hello, TSMutexCreate()); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_SSL_CLIENT_HELLO_HOOK, cb); } else { @@ -323,7 +323,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int } for (i = 0; i < client_hello_count_immediate; i++) { cb = TSContCreate(&CB_Client_Hello_Immediate, TSMutexCreate()); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_SSL_CLIENT_HELLO_HOOK, cb); } else { @@ -332,7 +332,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int } for (i = 0; i < sni_count; i++) { cb = TSContCreate(&CB_SNI, nullptr); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_SSL_SERVERNAME_HOOK, cb); } else { @@ -341,7 +341,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int } for (i = 0; i < cert_count; i++) { cb = TSContCreate(&CB_Cert, nullptr); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_SSL_CERT_HOOK, cb); } else { @@ -350,7 +350,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int } for (i = 0; i < cert_count_immediate; i++) { cb = TSContCreate(&CB_Cert_Immediate, nullptr); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_SSL_CERT_HOOK, cb); } else { @@ -360,7 +360,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int for (i = 0; i < close_count; i++) { cb = TSContCreate(&CB_close, nullptr); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_VCONN_CLOSE_HOOK, cb); } else { @@ -369,7 +369,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int } for (i = 0; i < out_start_count; i++) { cb = TSContCreate(&CB_out_start, nullptr); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_VCONN_OUTBOUND_START_HOOK, cb); } else { @@ -378,7 +378,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int } for (i = 0; i < out_start_delay_count; i++) { cb = TSContCreate(&CB_out_start_delay, nullptr); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_VCONN_OUTBOUND_START_HOOK, cb); } else { @@ -387,7 +387,7 @@ setup_callbacks(TSHttpTxn txn, int preaccept_count, int client_hello_count, int } for (i = 0; i < out_close_count; i++) { cb = TSContCreate(&CB_out_close, nullptr); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); if (txn) { TSHttpTxnHookAdd(txn, TS_VCONN_OUTBOUND_CLOSE_HOOK, cb); } else { diff --git a/tests/tools/plugins/ssl_verify_test.cc b/tests/tools/plugins/ssl_verify_test.cc index a0366633377..d375a078071 100644 --- a/tests/tools/plugins/ssl_verify_test.cc +++ b/tests/tools/plugins/ssl_verify_test.cc @@ -48,7 +48,7 @@ CB_server_verify(TSCont cont, TSEvent event, void *edata) // Is this a good name or not? TSEvent reenable_event = TS_EVENT_CONTINUE; TSSslConnection sslobj = TSVConnSslConnectionGet(ssl_vc); - SSL *ssl = (SSL *)sslobj; + SSL *ssl = reinterpret_cast(sslobj); const char *sni_name = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); if (sni_name) { std::string sni_string(sni_name); @@ -100,7 +100,7 @@ setup_callbacks(int count) TSDebug(PN, "Setup callbacks count=%d", count); for (i = 0; i < count; i++) { cb = TSContCreate(&CB_server_verify, TSMutexCreate()); - TSContDataSet(cb, (void *)(intptr_t)i); + TSContDataSet(cb, (void *)static_cast(i)); TSHttpHookAdd(TS_SSL_VERIFY_SERVER_HOOK, cb); } return; diff --git a/tests/tools/plugins/ssntxnorder_verify.cc b/tests/tools/plugins/ssntxnorder_verify.cc index 276fec95da6..ad856cdaf4f 100644 --- a/tests/tools/plugins/ssntxnorder_verify.cc +++ b/tests/tools/plugins/ssntxnorder_verify.cc @@ -25,10 +25,10 @@ #include #include #include -#include // for abort -#include // for debug -#include // for PRIu64 -#include +#include // for abort +#include // for debug +#include // for PRIu64 +#include // debug messages viewable by setting 'proxy.config.diags.debug.tags' // in 'records.config' @@ -95,7 +95,7 @@ static const char ctl_dump[] = "dump"; // output active ssn/txn tables cmd - SSN ID */ static void -dump_tables(void) +dump_tables() { TSDebug(DEBUG_TAG_HOOK, "Dumping active session and transaction tables."); std::stringstream dump(""); @@ -106,8 +106,8 @@ dump_tables(void) dump << "No active sessions could be found." << std::endl; } else { // Output for every active session - for (std::set::iterator it = started_ssns.begin(); it != started_ssns.end(); ++it) { - dump << "Session --> ID: " << *it << std::endl; + for (auto started_ssn : started_ssns) { + dump << "Session --> ID: " << started_ssn << std::endl; } } @@ -115,8 +115,8 @@ dump_tables(void) dump << "No active transactions could be found." << std::endl; } else { // Output for every active transaction - for (std::set::iterator it = started_txns.begin(); it != started_txns.end(); ++it) { - dump << "Transaction --> ID: " << it->id << " ; Enclosing SSN ID: " << it->ssnp << " ;" << std::endl; + for (const auto &it : started_txns) { + dump << "Transaction --> ID: " << it.id << " ; Enclosing SSN ID: " << it.ssnp << " ;" << std::endl; } } dump << std::string(100, '+') << std::endl; diff --git a/tests/tools/plugins/test_log_interface.cc b/tests/tools/plugins/test_log_interface.cc index 4e85fc07c6c..66b89c746f4 100644 --- a/tests/tools/plugins/test_log_interface.cc +++ b/tests/tools/plugins/test_log_interface.cc @@ -23,7 +23,7 @@ #include #include -#include +#include constexpr auto plugin_name = "test_log_interface"; @@ -40,7 +40,7 @@ is_get_request(TSHttpTxn transaction) } int method_len = 0; const char *method = TSHttpHdrMethodGet(req_bufp, req_loc, &method_len); - if (method_len != (int)strlen(TS_HTTP_METHOD_GET) || strncasecmp(method, TS_HTTP_METHOD_GET, method_len) != 0) { + if (method_len != static_cast(strlen(TS_HTTP_METHOD_GET)) || strncasecmp(method, TS_HTTP_METHOD_GET, method_len) != 0) { TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_loc); return false; } @@ -52,7 +52,7 @@ int global_handler(TSCont continuation, TSEvent event, void *data) { TSHttpSsn session = static_cast(data); - TSHttpTxn transaction = (TSHttpTxn)data; + TSHttpTxn transaction = static_cast(data); switch (event) { case TS_EVENT_HTTP_READ_REQUEST_HDR: diff --git a/tools/jtest/jtest.cc b/tools/jtest/jtest.cc index eaaa402e056..3f04a504149 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);