diff --git a/.clang-tidy b/.clang-tidy index 3eeb13a..2b65f16 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -48,6 +48,7 @@ Checks: ' -misc-redundant-expression, -misc-unused-parameters, -misc-use-anonymous-namespace, + -misc-use-internal-linkage, modernize-*, -modernize-avoid-c-arrays, -modernize-loop-convert, @@ -75,6 +76,7 @@ Checks: ' -readability-inconsistent-declaration-parameter-name, -readability-isolate-declaration, -readability-magic-numbers, + -readability-math-missing-parentheses, -readability-named-parameter, -readability-redundant-access-specifiers, -readability-redundant-declaration, diff --git a/src/cache.cpp b/src/cache.cpp index fd84594..66628f7 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -34,7 +34,7 @@ //------------------------------------------------------------------- // Utility //------------------------------------------------------------------- -inline void SetStatCacheTime(struct timespec& ts) +static inline void SetStatCacheTime(struct timespec& ts) { if(-1 == clock_gettime(static_cast(CLOCK_MONOTONIC_COARSE), &ts)){ S3FS_PRN_CRIT("clock_gettime failed: %d", errno); @@ -42,13 +42,13 @@ inline void SetStatCacheTime(struct timespec& ts) } } -inline void InitStatCacheTime(struct timespec& ts) +static inline void InitStatCacheTime(struct timespec& ts) { ts.tv_sec = 0; ts.tv_nsec = 0; } -inline int CompareStatCacheTime(const struct timespec& ts1, const struct timespec& ts2) +static inline int CompareStatCacheTime(const struct timespec& ts1, const struct timespec& ts2) { // return -1: ts1 < ts2 // 0: ts1 == ts2 @@ -67,7 +67,7 @@ inline int CompareStatCacheTime(const struct timespec& ts1, const struct timespe return 0; } -inline bool IsExpireStatCacheTime(const struct timespec& ts, const time_t& expire) +static inline bool IsExpireStatCacheTime(const struct timespec& ts, const time_t& expire) { struct timespec nowts; SetStatCacheTime(nowts); diff --git a/src/curl.cpp b/src/curl.cpp index 73fe3fa..ea4946e 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -173,9 +173,7 @@ bool S3fsCurl::InitS3fsCurl() // [NOTE] // sCurlPoolSize must be over parallel(or multireq) count. // - if(sCurlPoolSize < std::max(GetMaxParallelCount(), GetMaxMultiRequest())){ - sCurlPoolSize = std::max(GetMaxParallelCount(), GetMaxMultiRequest()); - } + sCurlPoolSize = std::max({sCurlPoolSize, GetMaxParallelCount(), GetMaxMultiRequest()}); sCurlPool = new CurlHandlerPool(sCurlPoolSize); if (!sCurlPool->Init()) { return false; diff --git a/src/fdcache_entity.cpp b/src/fdcache_entity.cpp index fda244b..23660b9 100644 --- a/src/fdcache_entity.cpp +++ b/src/fdcache_entity.cpp @@ -453,9 +453,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts orgmeta = *pmeta; size_orgmeta = get_size(orgmeta); } - if(new_size < size_orgmeta){ - size_orgmeta = new_size; - } + size_orgmeta = std::min(new_size, size_orgmeta); }else{ // diff --git a/src/fdcache_page.cpp b/src/fdcache_page.cpp index f5b50ef..0ccc694 100644 --- a/src/fdcache_page.cpp +++ b/src/fdcache_page.cpp @@ -40,7 +40,7 @@ static constexpr int CHECK_CACHEFILE_PART_SIZE = 1024 * 16; // Buffer size in // fdpage_list_t utility //------------------------------------------------ // Inline function for repeated processing -inline void raw_add_compress_fdpage_list(fdpage_list_t& pagelist, const fdpage& orgpage, bool ignore_load, bool ignore_modify, bool default_load, bool default_modify) +static inline void raw_add_compress_fdpage_list(fdpage_list_t& pagelist, const fdpage& orgpage, bool ignore_load, bool ignore_modify, bool default_load, bool default_modify) { if(0 < orgpage.bytes){ // [NOTE] diff --git a/src/s3fs.cpp b/src/s3fs.cpp index b340917..2257d78 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -2720,9 +2720,7 @@ static int s3fs_truncate(const char* _path, off_t size) FUSE_CTX_INFO("[path=%s][size=%lld]", path, static_cast(size)); - if(size < 0){ - size = 0; - } + size = std::max(size, 0); if(0 != (result = check_parent_object_access(path, X_OK))){ return result; @@ -3186,7 +3184,7 @@ static bool multi_head_callback(S3fsCurl* s3fscurl, void* param) } // Add stat cache - std::string saved_path = s3fscurl->GetSpecialSavedPath(); + const std::string& saved_path = s3fscurl->GetSpecialSavedPath(); if(!StatCache::getStatCacheData()->AddStat(saved_path, *(s3fscurl->GetResponseHeaders()))){ S3FS_PRN_ERR("failed adding stat cache [path=%s]", saved_path.c_str()); return false; @@ -3261,9 +3259,9 @@ static std::unique_ptr multi_head_retry_callback(S3fsCurl* s3fscurl) } std::unique_ptr newcurl(new S3fsCurl(s3fscurl->IsUseAhbe())); - std::string path = s3fscurl->GetBasePath(); - std::string base_path = s3fscurl->GetBasePath(); - std::string saved_path = s3fscurl->GetSpecialSavedPath(); + const std::string& path = s3fscurl->GetBasePath(); + const std::string& base_path = s3fscurl->GetBasePath(); + const std::string& saved_path = s3fscurl->GetSpecialSavedPath(); if(!newcurl->PreHeadRequest(path, base_path, saved_path, ssec_key_pos)){ S3FS_PRN_ERR("Could not duplicate curl object(%s).", saved_path.c_str()); @@ -3381,7 +3379,7 @@ static int readdir_multi_head(const char* path, const S3ObjList& head, void* buf for(s3obj_list_t::iterator reiter = notfound_param.notfound_list.begin(); reiter != notfound_param.notfound_list.end(); ++reiter){ int dir_result; - std::string dirpath = *reiter; + const std::string& dirpath = *reiter; if(-ENOTEMPTY == (dir_result = directory_empty(dirpath.c_str()))){ // Found objects under the path, so the path is directory. diff --git a/src/s3fs_global.cpp b/src/s3fs_global.cpp index 6139f30..af8f28a 100644 --- a/src/s3fs_global.cpp +++ b/src/s3fs_global.cpp @@ -20,6 +20,8 @@ #include +#include "common.h" + //------------------------------------------------------------------- // Global variables //------------------------------------------------------------------- diff --git a/src/string_util.cpp b/src/string_util.cpp index bd91c54..8f8ab1c 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -402,7 +402,7 @@ std::string s3fs_base64(const unsigned char* input, size_t length) return result; } -inline unsigned char char_decode64(const char ch) +static inline unsigned char char_decode64(const char ch) { unsigned char by; if('A' <= ch && ch <= 'Z'){ // A - Z