From c97f7a2a1373c9ff1f91bb2257aa67fd03889211 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Thu, 7 Mar 2024 01:04:22 +0900 Subject: [PATCH] Address clang-tidy 18 warnings (#2428) --- .clang-tidy | 1 + src/curl.cpp | 8 ++++---- src/fdcache_entity.cpp | 4 ++-- src/s3fs.cpp | 16 ++++++++-------- src/s3objlist.cpp | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 7c3a1a3f56..cb956f9384 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -61,6 +61,7 @@ Checks: ' -performance-no-int-to-ptr, portability-*, readability-*, + -readability-avoid-nested-conditional-operator, -readability-braces-around-statements, -readability-else-after-return, -readability-function-cognitive-complexity, diff --git a/src/curl.cpp b/src/curl.cpp index eeefdd1481..a54ed32ce5 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -609,7 +609,7 @@ size_t S3fsCurl::ReadCallback(void* ptr, size_t size, size_t nmemb, void* userp) memcpy(ptr, pCurl->postdata, copysize); pCurl->postdata_remaining = (pCurl->postdata_remaining > static_cast(copysize) ? (pCurl->postdata_remaining - copysize) : 0); - pCurl->postdata += static_cast(copysize); + pCurl->postdata += copysize; return copysize; } @@ -963,7 +963,7 @@ bool S3fsCurl::GetSseKey(std::string& md5, std::string& ssekey) bool S3fsCurl::GetSseKeyMd5(size_t pos, std::string& md5) { - if(S3fsCurl::sseckeys.size() <= static_cast(pos)){ + if(S3fsCurl::sseckeys.size() <= pos){ return false; } size_t cnt = 0; @@ -1526,7 +1526,7 @@ int S3fsCurl::ParallelMixMultipartUploadRequest(const char* tpath, headers_t& me for(off_t i = 0, bytes = 0; i < iter->bytes; i += bytes){ std::unique_ptr s3fscurl_para(new S3fsCurl(true)); - bytes = std::min(static_cast(GetMultipartCopySize()), iter->bytes - i); + bytes = std::min(GetMultipartCopySize(), iter->bytes - i); /* every part should be larger than MIN_MULTIPART_SIZE and smaller than FIVE_GB */ off_t remain_bytes = iter->bytes - i - bytes; @@ -3447,7 +3447,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd) std::string strMD5; if(-1 != fd){ strMD5 = s3fs_get_content_md5(fd); - if(0 == strMD5.length()){ + if(strMD5.empty()){ S3FS_PRN_ERR("Failed to make MD5."); return -EIO; } diff --git a/src/fdcache_entity.cpp b/src/fdcache_entity.cpp index 49d0ea34e5..68069c3861 100644 --- a/src/fdcache_entity.cpp +++ b/src/fdcache_entity.cpp @@ -1180,10 +1180,10 @@ int FdEntity::NoCacheLoadAndPost(PseudoFdInfo* pseudo_obj, off_t start, off_t si break; } // download each multipart size(default 10MB) in unit - for(off_t oneread = 0, totalread = (iter->offset < start ? start : 0); totalread < static_cast(iter->bytes); totalread += oneread){ + for(off_t oneread = 0, totalread = (iter->offset < start ? start : 0); totalread < iter->bytes; totalread += oneread){ int upload_fd = physical_fd; off_t offset = iter->offset + totalread; - oneread = std::min(static_cast(iter->bytes) - totalread, S3fsCurl::GetMultipartSize()); + oneread = std::min(iter->bytes - totalread, S3fsCurl::GetMultipartSize()); // check rest size is over minimum part size // diff --git a/src/s3fs.cpp b/src/s3fs.cpp index a082251c23..ca17fe727b 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -60,7 +60,7 @@ #define ENOATTR ENODATA #endif -enum class dirtype { +enum class dirtype : int8_t { UNKNOWN = -1, NEW = 0, OLD = 1, @@ -4040,7 +4040,7 @@ static int s3fs_getxattr(const char* path, const char* name, char* value, size_t const char* pvalue = xiter->second.c_str(); if(0 < size){ - if(static_cast(size) < length){ + if(size < length){ // over buffer size return -ERANGE; } @@ -4296,12 +4296,12 @@ static void* s3fs_init(struct fuse_conn_info* conn) // Investigate system capabilities #ifndef __APPLE__ - if((unsigned int)conn->capable & FUSE_CAP_ATOMIC_O_TRUNC){ + if(conn->capable & FUSE_CAP_ATOMIC_O_TRUNC){ conn->want |= FUSE_CAP_ATOMIC_O_TRUNC; } #endif - if((unsigned int)conn->capable & FUSE_CAP_BIG_WRITES){ + if(conn->capable & FUSE_CAP_BIG_WRITES){ conn->want |= FUSE_CAP_BIG_WRITES; } @@ -4725,7 +4725,7 @@ static fsblkcnt_t parse_bucket_size(char* max_size) if(!isdigit(*ptr)){ return 0; // wrong number } - n_bytes = static_cast(strtoull(max_size, nullptr, 10)); + n_bytes = strtoull(max_size, nullptr, 10); if((INT64_MAX / scale) < n_bytes){ return 0; // overflow } @@ -5199,7 +5199,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar return 0; } else if(is_prefix(arg, "multipart_size=")){ - off_t size = static_cast(cvt_strtoofft(strchr(arg, '=') + sizeof(char), /*base=*/ 10)); + off_t size = cvt_strtoofft(strchr(arg, '=') + sizeof(char), /*base=*/ 10); if(!S3fsCurl::SetMultipartSize(size)){ S3FS_PRN_EXIT("multipart_size option must be at least 5 MB."); return -1; @@ -5207,7 +5207,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar return 0; } else if(is_prefix(arg, "multipart_copy_size=")){ - off_t size = static_cast(cvt_strtoofft(strchr(arg, '=') + sizeof(char), /*base=*/ 10)); + off_t size = cvt_strtoofft(strchr(arg, '=') + sizeof(char), /*base=*/ 10); if(!S3fsCurl::SetMultipartCopySize(size)){ S3FS_PRN_EXIT("multipart_copy_size option must be at least 5 MB."); return -1; @@ -5215,7 +5215,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar return 0; } else if(is_prefix(arg, "max_dirty_data=")){ - off_t size = static_cast(cvt_strtoofft(strchr(arg, '=') + sizeof(char), /*base=*/ 10)); + off_t size = cvt_strtoofft(strchr(arg, '=') + sizeof(char), /*base=*/ 10); if(size >= 50){ size *= 1024 * 1024; }else if(size != -1){ diff --git a/src/s3objlist.cpp b/src/s3objlist.cpp index 592c99da17..4a3ed59763 100644 --- a/src/s3objlist.cpp +++ b/src/s3objlist.cpp @@ -197,7 +197,7 @@ bool S3ObjList::GetLastName(std::string& lastname) const bool result = false; lastname = ""; for(s3obj_t::const_iterator iter = objects.begin(); iter != objects.end(); ++iter){ - if((*iter).second.orgname.length()){ + if(!iter->second.orgname.empty()){ if(lastname.compare(iter->second.orgname) < 0){ lastname = (*iter).second.orgname; result = true;