From 3e242d0bad82e468638063df39f5ff118078c4c2 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sat, 30 Jul 2022 22:35:27 +0900 Subject: [PATCH] Avoid C-style casts (#2015) Prefer more precise C++-style casts. --- .clang-tidy | 1 + src/curl_multi.cpp | 8 ++++---- src/fdcache_fdinfo.cpp | 8 ++++---- src/s3fs_xml.cpp | 10 +++++----- src/threadpoolman.cpp | 11 +++++------ 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 8d7f99f..8f07838 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,6 +7,7 @@ Checks: ' -bugprone-macro-parentheses, -bugprone-narrowing-conversions, -bugprone-unhandled-self-assignment, + cppcoreguidelines-pro-type-cstyle-cast, google-*, -google-build-using-namespace, -google-readability-casting, diff --git a/src/curl_multi.cpp b/src/curl_multi.cpp index c30fc30..bedaa47 100644 --- a/src/curl_multi.cpp +++ b/src/curl_multi.cpp @@ -140,9 +140,9 @@ int S3fsMultiCurl::MultiPerform() success = false; S3FS_PRN_ERR("failed pthread_join - rc(%d) %s", rc, strerror(rc)); } else { - int int_retval = (int)(intptr_t)(retval); + long int_retval = reinterpret_cast(retval); if (int_retval && !(int_retval == -ENOENT && isMultiHead)) { - S3FS_PRN_WARN("thread terminated with non-zero return code: %d", int_retval); + S3FS_PRN_WARN("thread terminated with non-zero return code: %ld", int_retval); } } } @@ -176,9 +176,9 @@ int S3fsMultiCurl::MultiPerform() success = false; S3FS_PRN_ERR("failed pthread_join - rc(%d)", rc); } else { - int int_retval = (int)(intptr_t)(retval); + long int_retval = reinterpret_cast(retval); if (int_retval && !(int_retval == -ENOENT && isMultiHead)) { - S3FS_PRN_WARN("thread terminated with non-zero return code: %d", int_retval); + S3FS_PRN_WARN("thread terminated with non-zero return code: %ld", int_retval); } } } diff --git a/src/fdcache_fdinfo.cpp b/src/fdcache_fdinfo.cpp index b033f5d..1c14076 100644 --- a/src/fdcache_fdinfo.cpp +++ b/src/fdcache_fdinfo.cpp @@ -52,7 +52,7 @@ void* PseudoFdInfo::MultipartUploadThreadWorker(void* arg) if(pthparam){ delete pthparam; } - return (void*)(intptr_t)(-EIO); + return reinterpret_cast(-EIO); } S3FS_PRN_INFO3("Upload Part Thread [tpath=%s][start=%lld][size=%lld][part=%d]", pthparam->path.c_str(), static_cast(pthparam->start), static_cast(pthparam->size), pthparam->part_num); @@ -68,7 +68,7 @@ void* PseudoFdInfo::MultipartUploadThreadWorker(void* arg) result = -EIO; } delete pthparam; - return (void*)(intptr_t)(result); + return reinterpret_cast(result); } } @@ -81,7 +81,7 @@ void* PseudoFdInfo::MultipartUploadThreadWorker(void* arg) result = -EIO; } delete pthparam; - return (void*)(intptr_t)(result); + return reinterpret_cast(result); } // Send request and get result @@ -103,7 +103,7 @@ void* PseudoFdInfo::MultipartUploadThreadWorker(void* arg) } delete pthparam; - return (void*)(intptr_t)(result); + return reinterpret_cast(result); } //------------------------------------------------ diff --git a/src/s3fs_xml.cpp b/src/s3fs_xml.cpp index 8aae1e3..7f0dd89 100644 --- a/src/s3fs_xml.cpp +++ b/src/s3fs_xml.cpp @@ -153,7 +153,7 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path) // basepath(path) is as same as fullpath. if(0 == strcmp(reinterpret_cast(fullpath), path)){ xmlFree(fullpath); - return (char*)c_strErrorObjectName; + return const_cast(c_strErrorObjectName); } // Make dir path and filename @@ -172,15 +172,15 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path) if(0 < strlen(dirpath)){ // case of "/" if(0 == strcmp(mybname, "/") && 0 == strcmp(dirpath, "/")){ - return (char*)c_strErrorObjectName; + return const_cast(c_strErrorObjectName); } // case of "." if(0 == strcmp(mybname, ".") && 0 == strcmp(dirpath, ".")){ - return (char*)c_strErrorObjectName; + return const_cast(c_strErrorObjectName); } // case of ".." if(0 == strcmp(mybname, "..") && 0 == strcmp(dirpath, ".")){ - return (char*)c_strErrorObjectName; + return const_cast(c_strErrorObjectName); } // case of "name" if(0 == strcmp(dirpath, ".")){ @@ -206,7 +206,7 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path) } } // case of something wrong - return (char*)c_strErrorObjectName; + return const_cast(c_strErrorObjectName); } static xmlChar* get_exp_value_xml(xmlDocPtr doc, xmlXPathContextPtr ctx, const char* exp_key) diff --git a/src/threadpoolman.cpp b/src/threadpoolman.cpp index 46de268..1696e6c 100644 --- a/src/threadpoolman.cpp +++ b/src/threadpoolman.cpp @@ -71,7 +71,7 @@ void* ThreadPoolMan::Worker(void* arg) if(!psingleton){ S3FS_PRN_ERR("The parameter for worker thread is invalid."); - return (void*)(intptr_t)(-EIO); + return reinterpret_cast(-EIO); } S3FS_PRN_INFO3("Start worker thread in ThreadPoolMan."); @@ -102,9 +102,8 @@ void* ThreadPoolMan::Worker(void* arg) if(pparam){ void* retval = pparam->pfunc(pparam->args); - int int_retval = (int)(intptr_t)(retval); - if(0 != int_retval){ - S3FS_PRN_WARN("The instruction function returned with somthign error code(%d).", int_retval); + if(NULL != retval){ + S3FS_PRN_WARN("The instruction function returned with somthign error code(%ld).", reinterpret_cast(retval)); } if(pparam->psem){ pparam->psem->post(); @@ -113,7 +112,7 @@ void* ThreadPoolMan::Worker(void* arg) } } - return (void*)(intptr_t)(0); + return NULL; } //------------------------------------------------ @@ -210,7 +209,7 @@ bool ThreadPoolMan::StopThreads() if(result){ S3FS_PRN_ERR("failed pthread_join - result(%d)", result); }else{ - S3FS_PRN_DBG("succeed pthread_join - return code(%d)", (int)(intptr_t)(retval)); + S3FS_PRN_DBG("succeed pthread_join - return code(%ld)", reinterpret_cast(retval)); } } thread_list.clear();