Skip to content

Commit

Permalink
Ran make clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
bryancall committed Aug 19, 2019
1 parent 191d794 commit 4cfd5a7
Show file tree
Hide file tree
Showing 310 changed files with 2,756 additions and 2,621 deletions.
28 changes: 14 additions & 14 deletions example/plugins/c-api/cache_scan/cache_scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ using cache_scan_state = struct cache_scan_state_t;
static int
handle_scan(TSCont contp, TSEvent event, void *edata)
{
cache_scan_state *cstate = (cache_scan_state *)TSContDataGet(contp);
cache_scan_state *cstate = static_cast<cache_scan_state *>(TSContDataGet(contp));

if (event == TS_EVENT_CACHE_REMOVE) {
cstate->done = 1;
const char error[] = "Cache remove operation succeeded";
cstate->cache_vc = (TSVConn)edata;
cstate->cache_vc = static_cast<TSVConn>(edata);
cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX);
cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1);
TSVIONBytesSet(cstate->write_vio, cstate->total_bytes);
Expand All @@ -83,7 +83,7 @@ handle_scan(TSCont contp, TSEvent event, void *edata)
const char error[] = "Cache remove operation failed error=";
char rc[12];
snprintf(rc, 12, "%p", edata);
cstate->cache_vc = (TSVConn)edata;
cstate->cache_vc = static_cast<TSVConn>(edata);
cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX);
cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1);
cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, rc, strlen(rc));
Expand All @@ -95,7 +95,7 @@ handle_scan(TSCont contp, TSEvent event, void *edata)

// first scan event, save vc and start write
if (event == TS_EVENT_CACHE_SCAN) {
cstate->cache_vc = (TSVConn)edata;
cstate->cache_vc = static_cast<TSVConn>(edata);
cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX);
return TS_EVENT_CONTINUE;
}
Expand All @@ -119,7 +119,7 @@ handle_scan(TSCont contp, TSEvent event, void *edata)
if (cstate->done) {
return TS_CACHE_SCAN_RESULT_DONE;
}
TSCacheHttpInfo cache_infop = (TSCacheHttpInfo)edata;
TSCacheHttpInfo cache_infop = static_cast<TSCacheHttpInfo>(edata);

TSMBuffer req_bufp, resp_bufp;
TSMLoc req_hdr_loc, resp_hdr_loc;
Expand Down Expand Up @@ -182,7 +182,7 @@ handle_scan(TSCont contp, TSEvent event, void *edata)
static int
handle_accept(TSCont contp, TSEvent event, TSVConn vc)
{
cache_scan_state *cstate = (cache_scan_state *)TSContDataGet(contp);
cache_scan_state *cstate = static_cast<cache_scan_state *>(TSContDataGet(contp));

if (event == TS_EVENT_NET_ACCEPT) {
if (cstate) {
Expand Down Expand Up @@ -214,7 +214,7 @@ static void
cleanup(TSCont contp)
{
// shutdown vc and free memory
cache_scan_state *cstate = (cache_scan_state *)TSContDataGet(contp);
cache_scan_state *cstate = static_cast<cache_scan_state *>(TSContDataGet(contp));

if (cstate) {
// cancel any pending cache scan actions, since we will be destroying the
Expand Down Expand Up @@ -254,7 +254,7 @@ cleanup(TSCont contp)
static int
handle_io(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */)
{
cache_scan_state *cstate = (cache_scan_state *)TSContDataGet(contp);
cache_scan_state *cstate = static_cast<cache_scan_state *>(TSContDataGet(contp));

switch (event) {
case TS_EVENT_VCONN_READ_READY:
Expand Down Expand Up @@ -315,7 +315,7 @@ cache_intercept(TSCont contp, TSEvent event, void *edata)
switch (event) {
case TS_EVENT_NET_ACCEPT:
case TS_EVENT_NET_ACCEPT_FAILED:
return handle_accept(contp, event, (TSVConn)edata);
return handle_accept(contp, event, static_cast<TSVConn>(edata));
case TS_EVENT_VCONN_READ_READY:
case TS_EVENT_VCONN_READ_COMPLETE:
case TS_EVENT_VCONN_WRITE_READY:
Expand Down Expand Up @@ -358,7 +358,7 @@ unescapifyStr(char *buffer)
if (*read == '%' && *(read + 1) != '\0' && *(read + 2) != '\0') {
subStr[0] = *(++read);
subStr[1] = *(++read);
*write = (char)strtol(subStr, (char **)nullptr, 16);
*write = static_cast<char>(strtol(subStr, (char **)nullptr, 16));
read++;
write++;
} else if (*read == '+') {
Expand Down Expand Up @@ -417,13 +417,13 @@ setup_request(TSCont contp, TSHttpTxn txnp)
if (path_len == 10 && !strncmp(path, "show-cache", 10)) {
scan_contp = TSContCreate(cache_intercept, TSMutexCreate());
TSHttpTxnIntercept(scan_contp, txnp);
cstate = (cache_scan_state *)TSmalloc(sizeof(cache_scan_state));
cstate = static_cast<cache_scan_state *>(TSmalloc(sizeof(cache_scan_state)));
memset(cstate, 0, sizeof(cache_scan_state));
cstate->http_txnp = txnp;

if (query && query_len > 11) {
char querybuf[2048];
query_len = (unsigned)query_len > sizeof(querybuf) - 1 ? sizeof(querybuf) - 1 : query_len;
query_len = static_cast<unsigned>(query_len) > sizeof(querybuf) - 1 ? sizeof(querybuf) - 1 : query_len;
char *start = querybuf, *end = querybuf + query_len;
size_t del_url_len;
memcpy(querybuf, query, query_len);
Expand Down Expand Up @@ -481,11 +481,11 @@ cache_print_plugin(TSCont contp, TSEvent event, void *edata)
{
switch (event) {
case TS_EVENT_HTTP_READ_REQUEST_HDR:
return setup_request(contp, (TSHttpTxn)edata);
return setup_request(contp, static_cast<TSHttpTxn>(edata));
default:
break;
}
TSHttpTxnReenable((TSHttpTxn)edata, TS_EVENT_HTTP_CONTINUE);
TSHttpTxnReenable(static_cast<TSHttpTxn>(edata), TS_EVENT_HTTP_CONTINUE);
return TS_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion example/plugins/c-api/cert_update/cert_update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
limitations under the License.
*/

#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <string>
#include <string_view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
limitations under the License.
*/

#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <string>
#include <string_view>
Expand Down
4 changes: 2 additions & 2 deletions example/plugins/c-api/protocol/Protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ accept_handler(TSCont contp, TSEvent event, void *edata)
case TS_EVENT_NET_ACCEPT:
/* Create a new mutex for the TxnSM, which is going
to handle the incoming request. */
pmutex = (TSMutex)TSMutexCreate();
txn_sm = (TSCont)TxnSMCreate(pmutex, (TSVConn)edata, server_port);
pmutex = TSMutexCreate();
txn_sm = TxnSMCreate(pmutex, (TSVConn)edata, server_port);

/* This is no reason for not grabbing the lock.
So skip the routine which handle LockTry failure case. */
Expand Down
7 changes: 3 additions & 4 deletions example/plugins/c-api/protocol/TxnSM.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ state_start(TSCont contp, TSEvent event ATS_UNUSED, void *data ATS_UNUSED)
INT64_MAX, so that we will always get TS_EVENT_VCONN_READ_READY
event, but never TS_EVENT_VCONN_READ_COMPLETE event. */
set_handler(txn_sm->q_current_handler, (TxnSMHandler)&state_interface_with_client);
txn_sm->q_client_read_vio = TSVConnRead(txn_sm->q_client_vc, (TSCont)contp, txn_sm->q_client_request_buffer, INT64_MAX);
txn_sm->q_client_read_vio = TSVConnRead(txn_sm->q_client_vc, contp, txn_sm->q_client_request_buffer, INT64_MAX);

return TS_SUCCESS;
}
Expand Down Expand Up @@ -239,7 +239,7 @@ state_read_request_from_client(TSCont contp, TSEvent event, TSVIO vio ATS_UNUSED

/* Start to do cache lookup */
TSDebug(PLUGIN_NAME, "Key material: file name is %s*****", txn_sm->q_file_name);
txn_sm->q_key = (TSCacheKey)CacheKeyCreate(txn_sm->q_file_name);
txn_sm->q_key = CacheKeyCreate(txn_sm->q_file_name);

set_handler(txn_sm->q_current_handler, (TxnSMHandler)&state_handle_cache_lookup);
txn_sm->q_pending_action = TSCacheRead(contp, txn_sm->q_key);
Expand Down Expand Up @@ -908,8 +908,7 @@ send_response_to_client(TSCont contp)
TSDebug(PLUGIN_NAME, " . resp_len is %d", response_len);

set_handler(txn_sm->q_current_handler, (TxnSMHandler)&state_interface_with_client);
txn_sm->q_client_write_vio =
TSVConnWrite(txn_sm->q_client_vc, (TSCont)contp, txn_sm->q_client_response_buffer_reader, response_len);
txn_sm->q_client_write_vio = TSVConnWrite(txn_sm->q_client_vc, contp, txn_sm->q_client_response_buffer_reader, response_len);
return TS_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion example/plugins/c-api/protocol_stack/protocol_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
static int
proto_stack_cb(TSCont contp ATS_UNUSED, TSEvent event, void *edata)
{
TSHttpTxn txnp = (TSHttpTxn)edata;
TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
const char *results[10];
int count = 0;
TSDebug(PLUGIN_NAME, "Protocols:");
Expand Down
2 changes: 1 addition & 1 deletion example/plugins/c-api/query_remap/query_remap.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh ATS_UNUSED, TSRemapRequestInfo *rri)
int hostidx = -1;

/* make a copy of the query, as it is read only */
q = (char *)TSstrndup(req_query, req_query_len + 1);
q = TSstrndup(req_query, req_query_len + 1);

/* parse query parameters */
for (key = strtok_r(q, "&", &s); key != NULL;) {
Expand Down
14 changes: 7 additions & 7 deletions example/plugins/c-api/remap/remap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pthread_mutex_t remap_entry::mutex; /* remap_entry class mutex */
/* ----------------------- remap_entry::remap_entry ------------------------ */
remap_entry::remap_entry(int _argc, char *_argv[]) : next(nullptr), argc(0), argv(nullptr)
{
if (_argc > 0 && _argv && (argv = (char **)TSmalloc(sizeof(char *) * (_argc + 1))) != nullptr) {
if (_argc > 0 && _argv && (argv = static_cast<char **>(TSmalloc(sizeof(char *) * (_argc + 1)))) != nullptr) {
int i;
argc = _argc;
for (i = 0; i < argc; i++) {
Expand Down Expand Up @@ -145,7 +145,7 @@ TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
if (unlikely(api_info->size < sizeof(TSRemapInterface))) {
return store_my_error_message(TS_ERROR, errbuf, errbuf_size,
"Incorrect size of TSRemapInterface structure %d. Should be at least %d bytes",
(int)api_info->size, (int)sizeof(TSRemapInterface));
static_cast<int>(api_info->size), static_cast<int>(sizeof(TSRemapInterface)));
}
if (unlikely(api_info->tsremap_version < TSREMAP_VERSION)) {
return store_my_error_message(TS_ERROR, errbuf, errbuf_size, "Incorrect API version %d.%d", (api_info->tsremap_version >> 16),
Expand Down Expand Up @@ -269,18 +269,18 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
// How to store plugin private arguments inside Traffic Server request processing block.
if (TSHttpTxnArgIndexReserve("remap_example", "Example remap plugin", &arg_index) == TS_SUCCESS) {
TSDebug(PLUGIN_NAME, "Save processing counter %" PRIu64 " inside request processing block\n", _processing_counter);
TSHttpTxnArgSet((TSHttpTxn)rh, arg_index, (void *)_processing_counter); // save counter
TSHttpTxnArgSet(rh, arg_index, (void *)_processing_counter); // save counter
}
// How to cancel request processing and return error message to the client
// We will do it every other request
if (_processing_counter & 1) {
char *tmp = (char *)TSmalloc(256);
char *tmp = static_cast<char *>(TSmalloc(256));
static int my_local_counter = 0;

len = snprintf(tmp, 255, "This is very small example of TS API usage!\nIteration %d!\nHTTP return code %d\n", my_local_counter,
TS_HTTP_STATUS_CONTINUE + my_local_counter);
TSHttpTxnStatusSet((TSHttpTxn)rh, (TSHttpStatus)((int)TS_HTTP_STATUS_CONTINUE + my_local_counter));
TSHttpTxnErrorBodySet((TSHttpTxn)rh, tmp, len, nullptr); // Defaults to text/html
TSHttpTxnStatusSet(rh, static_cast<TSHttpStatus>(static_cast<int>(TS_HTTP_STATUS_CONTINUE) + my_local_counter));
TSHttpTxnErrorBodySet(rh, tmp, len, nullptr); // Defaults to text/html
my_local_counter++;
}
// hardcoded case for remapping
Expand Down Expand Up @@ -321,7 +321,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
void
TSRemapOSResponse(void *ih ATS_UNUSED, TSHttpTxn rh, int os_response_type)
{
void *data = TSHttpTxnArgGet((TSHttpTxn)rh, arg_index); // read counter (we store it in TSRemapDoRemap function call)
void *data = TSHttpTxnArgGet(rh, arg_index); // read counter (we store it in TSRemapDoRemap function call)
int request_id = data ? static_cast<int *>(data)[0] : -1;

TSDebug(PLUGIN_NAME, "Read processing counter %d from request processing block\n", request_id);
Expand Down
2 changes: 1 addition & 1 deletion example/plugins/c-api/secure_link/secure_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)

qh = TSUrlHttpQueryGet(rri->requestBufp, rri->requestUrl, &len);
if (qh && len > 0) {
s = (char *)TSstrndup(qh, len);
s = TSstrndup(qh, len);
if ((ptr = strtok_r(s, "&", &saveptr)) != NULL) {
do {
if ((val = strchr(ptr, '=')) != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion example/plugins/c-api/thread_pool/psi.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ _basename(const char *filename)
char *cptr;
const char *ptr = filename;

while ((cptr = strchr(ptr, (int)'/')) != NULL) {
while ((cptr = strchr(ptr, '/')) != NULL) {
ptr = cptr + 1;
}
return ptr;
Expand Down
4 changes: 2 additions & 2 deletions example/plugins/c-api/vconn_args/vconn_args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ vconn_arg_handler(TSCont contp, TSEvent event, void *edata)
// Testing set argument
int idx = 0;
while (TSVConnArgIndexReserve(PLUGIN_NAME, "test", &idx) == TS_SUCCESS) {
char *buf = (char *)TSmalloc(64);
char *buf = static_cast<char *>(TSmalloc(64));
snprintf(buf, 64, "Test Arg Idx %d", idx);
TSVConnArgSet(ssl_vc, idx, (void *)buf);
TSDebug(PLUGIN_NAME, "Successfully reserve and set arg #%d", idx);
Expand All @@ -65,7 +65,7 @@ vconn_arg_handler(TSCont contp, TSEvent event, void *edata)
// Testing argget and delete
int idx = 0;
while (idx <= last_arg) {
char *buf = (char *)TSVConnArgGet(ssl_vc, idx);
char *buf = static_cast<char *>(TSVConnArgGet(ssl_vc, idx));
if (buf) {
TSDebug(PLUGIN_NAME, "Successfully retrieve vconn arg #%d: %s", idx, buf);
TSfree(buf);
Expand Down
2 changes: 1 addition & 1 deletion example/plugins/c-api/verify_cert/verify_cert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ debug_certificate(const char *msg, X509_NAME *name)
long len;
char *ptr;
len = BIO_get_mem_data(bio, &ptr);
TSDebug(PLUGIN_NAME, "%s %.*s", msg, (int)len, ptr);
TSDebug(PLUGIN_NAME, "%s %.*s", msg, static_cast<int>(len), ptr);
}

BIO_free(bio);
Expand Down
6 changes: 3 additions & 3 deletions example/plugins/cpp-api/websocket/WSBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ WSBuffer::ws_digest(std::string const &key)
char digest_buf[WS_DIGEST_MAX];
size_t digest_len = 0;

if (TSBase64Encode((char *)hash_buf, hash_len, digest_buf, WS_DIGEST_MAX, &digest_len) != TS_SUCCESS) {
if (TSBase64Encode(reinterpret_cast<char *>(hash_buf), hash_len, digest_buf, WS_DIGEST_MAX, &digest_len) != TS_SUCCESS) {
return "base64encode-failed";
}

Expand Down Expand Up @@ -244,9 +244,9 @@ WSBuffer::get_closing_code(std::string const &message, std::string *desc)
{
uint16_t code = 0;
if (message.size() >= 2) {
code = (unsigned char)message[0];
code = static_cast<unsigned char>(message[0]);
code <<= 8;
code += (unsigned char)message[1];
code += static_cast<unsigned char>(message[1]);
if (desc) {
*desc = message.substr(2);
}
Expand Down
4 changes: 2 additions & 2 deletions include/tscpp/api/Headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class HeaderField
* @param an iterator which points to a single HeaderField value.
* @return true if the header value was successfully erased.
*/
bool erase(iterator it);
bool erase(const iterator &it);

/**
* Append a value or a separated list of values to this HeaderField
Expand Down Expand Up @@ -473,7 +473,7 @@ class Headers : noncopyable
* @param an iterator pointing to a header field.
* @return true if the header field pointed to by the iterator was erased.
*/
bool erase(iterator it);
bool erase(const iterator &it);

/**
* Erase all headers whose name matches key (this is a case insensitive match).
Expand Down
14 changes: 7 additions & 7 deletions iocore/aio/AIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ aio_stats_cb(const char * /* name ATS_UNUSED */, RecDataT data_type, RecData *da
diff = new_val - sum;
RecSetGlobalRawStatSum(aio_rsb, id, new_val);
RecSetGlobalRawStatCount(aio_rsb, id, now);
data->rec_float = (float)diff * 1000.00 / (float)time_diff;
data->rec_float = static_cast<float>(diff) * 1000.00 / static_cast<float>(time_diff);
return 0;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ ink_aio_init(ts::ModuleVersion v)
{
ink_release_assert(v.check(AIO_MODULE_INTERNAL_VERSION));

aio_rsb = RecAllocateRawStatBlock((int)AIO_STAT_COUNT);
aio_rsb = RecAllocateRawStatBlock(static_cast<int>(AIO_STAT_COUNT));
RecRegisterRawStat(aio_rsb, RECT_PROCESS, "proxy.process.cache.read_per_sec", RECD_FLOAT, RECP_PERSISTENT,
(int)AIO_STAT_READ_PER_SEC, aio_stats_cb);
RecRegisterRawStat(aio_rsb, RECT_PROCESS, "proxy.process.cache.write_per_sec", RECD_FLOAT, RECP_PERSISTENT,
Expand Down Expand Up @@ -382,9 +382,9 @@ cache_op(AIOCallbackInternal *op)
while (a->aio_nbytes - res > 0) {
do {
if (read) {
err = pread(a->aio_fildes, ((char *)a->aio_buf) + res, a->aio_nbytes - res, a->aio_offset + res);
err = pread(a->aio_fildes, (static_cast<char *>(a->aio_buf)) + res, a->aio_nbytes - res, a->aio_offset + res);
} else {
err = pwrite(a->aio_fildes, ((char *)a->aio_buf) + res, a->aio_nbytes - res, a->aio_offset + res);
err = pwrite(a->aio_fildes, (static_cast<char *>(a->aio_buf)) + res, a->aio_nbytes - res, a->aio_offset + res);
}
} while ((err < 0) && (errno == EINTR || errno == ENOBUFS || errno == ENOMEM));
if (err <= 0) {
Expand Down Expand Up @@ -432,8 +432,8 @@ ink_aio_thread_num_set(int thread_num)
void *
aio_thread_main(void *arg)
{
AIOThreadInfo *thr_info = (AIOThreadInfo *)arg;
AIO_Reqs *my_aio_req = (AIO_Reqs *)thr_info->req;
AIOThreadInfo *thr_info = static_cast<AIOThreadInfo *>(arg);
AIO_Reqs *my_aio_req = thr_info->req;
AIO_Reqs *current_req = nullptr;
AIOCallback *op = nullptr;
ink_mutex_acquire(&my_aio_req->aio_mutex);
Expand Down Expand Up @@ -464,7 +464,7 @@ aio_thread_main(void *arg)
}
ink_mutex_release(&current_req->aio_mutex);
cache_op((AIOCallbackInternal *)op);
ink_atomic_increment((int *)&current_req->requests_queued, -1);
ink_atomic_increment(&current_req->requests_queued, -1);
#ifdef AIO_STATS
ink_atomic_increment((int *)&current_req->pending, -1);
#endif
Expand Down
Loading

0 comments on commit 4cfd5a7

Please sign in to comment.