From 54aa278df0082ac217a767a8a6dcdc1e623dd576 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Thu, 25 Jan 2024 00:46:45 +0900 Subject: [PATCH] Fixed errors reported by cppcheck 2.13.0 (#2400) --- src/fdcache.cpp | 4 ++-- src/fdcache_fdinfo.cpp | 2 +- src/fdcache_fdinfo.h | 2 +- src/s3fs.cpp | 12 ++++++------ src/s3fs_util.cpp | 2 +- src/string_util.cpp | 2 +- src/string_util.h | 2 +- src/test_curl_util.cpp | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/fdcache.cpp b/src/fdcache.cpp index a4f4b73..2d4c4f8 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -431,7 +431,7 @@ bool FdManager::HasOpenEntityFd(const char* path) { AutoLock auto_lock(&FdManager::fd_manager_lock); - FdEntity* ent; + const FdEntity* ent; int fd = -1; if(nullptr == (ent = FdManager::singleton.GetFdEntity(path, fd, false, AutoLock::ALREADY_LOCKED))){ return false; @@ -916,7 +916,7 @@ bool FdManager::RawCheckAllCache(FILE* fp, const char* cache_stat_top_dir, const } // loop in directory of cache file's stats - struct dirent* pdirent = nullptr; + const struct dirent* pdirent = nullptr; while(nullptr != (pdirent = readdir(statsdir))){ if(DT_DIR == pdirent->d_type){ // found directory diff --git a/src/fdcache_fdinfo.cpp b/src/fdcache_fdinfo.cpp index bca631c..c71dbb7 100644 --- a/src/fdcache_fdinfo.cpp +++ b/src/fdcache_fdinfo.cpp @@ -683,7 +683,7 @@ bool PseudoFdInfo::CancelAllThreads() // [NOTE] // Maximum multipart upload size must be uploading boundary. // -bool PseudoFdInfo::ExtractUploadPartsFromUntreatedArea(off_t& untreated_start, off_t& untreated_size, mp_part_list_t& to_upload_list, filepart_list_t& cancel_upload_list, off_t max_mp_size) +bool PseudoFdInfo::ExtractUploadPartsFromUntreatedArea(const off_t& untreated_start, const off_t& untreated_size, mp_part_list_t& to_upload_list, filepart_list_t& cancel_upload_list, off_t max_mp_size) { if(untreated_start < 0 || untreated_size <= 0){ S3FS_PRN_ERR("Paramters are wrong(untreated_start=%lld, untreated_size=%lld).", static_cast(untreated_start), static_cast(untreated_size)); diff --git a/src/fdcache_fdinfo.h b/src/fdcache_fdinfo.h index de23d17..0f1bcc8 100644 --- a/src/fdcache_fdinfo.h +++ b/src/fdcache_fdinfo.h @@ -86,7 +86,7 @@ class PseudoFdInfo bool ParallelMultipartUpload(const char* path, const mp_part_list_t& mplist, bool is_copy, AutoLock::Type type = AutoLock::NONE); bool InsertUploadPart(off_t start, off_t size, int part_num, bool is_copy, etagpair** ppetag, AutoLock::Type type = AutoLock::NONE); bool CancelAllThreads(); - bool ExtractUploadPartsFromUntreatedArea(off_t& untreated_start, off_t& untreated_size, mp_part_list_t& to_upload_list, filepart_list_t& cancel_upload_list, off_t max_mp_size); + bool ExtractUploadPartsFromUntreatedArea(const off_t& untreated_start, const off_t& untreated_size, mp_part_list_t& to_upload_list, filepart_list_t& cancel_upload_list, off_t max_mp_size); public: explicit PseudoFdInfo(int fd = -1, int open_flags = 0); diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 67fc8d3..f2c529b 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -820,7 +820,7 @@ static int check_object_owner(const char* path, struct stat* pstbuf) int result; struct stat st; struct stat* pst = (pstbuf ? pstbuf : &st); - struct fuse_context* pcxt; + const struct fuse_context* pcxt; S3FS_PRN_DBG("[path=%s]", path); @@ -1019,7 +1019,7 @@ static int s3fs_getattr(const char* _path, struct stat* stbuf) // (See: Issue 241) if(stbuf){ AutoFdEntity autoent; - FdEntity* ent; + const FdEntity* ent; if(nullptr != (ent = autoent.OpenExistFdEntity(path))){ struct stat tmpstbuf; if(ent->GetStats(tmpstbuf)){ @@ -1151,7 +1151,7 @@ static int s3fs_create(const char* _path, mode_t mode, struct fuse_file_info* fi { WTF8_ENCODE(path) int result; - struct fuse_context* pcxt; + const struct fuse_context* pcxt; FUSE_CTX_INFO("[path=%s][mode=%04o][flags=0x%x]", path, mode, fi->flags); @@ -1405,7 +1405,7 @@ static int s3fs_symlink(const char* _from, const char* _to) WTF8_ENCODE(from) WTF8_ENCODE(to) int result; - struct fuse_context* pcxt; + const struct fuse_context* pcxt; FUSE_CTX_INFO("[from=%s][to=%s]", from, to); @@ -2783,7 +2783,7 @@ static int s3fs_truncate(const char* _path, off_t size) }else{ // Not found -> Make tmpfile(with size) - struct fuse_context* pcxt; + const struct fuse_context* pcxt; if(nullptr == (pcxt = fuse_get_context())){ return -EIO; } @@ -4770,7 +4770,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar } if(!nonempty){ - struct dirent *ent; + const struct dirent *ent; DIR *dp = opendir(mountpoint.c_str()); if(dp == nullptr){ S3FS_PRN_EXIT("failed to open MOUNTPOINT: %s: %s", mountpoint.c_str(), strerror(errno)); diff --git a/src/s3fs_util.cpp b/src/s3fs_util.cpp index 1b7d451..1096b22 100644 --- a/src/s3fs_util.cpp +++ b/src/s3fs_util.cpp @@ -400,7 +400,7 @@ bool compare_sysname(const char* target) // The buffer size of sysname member in struct utsname is // OS dependent, but 512 bytes is sufficient for now. // - static char* psysname = nullptr; + static const char* psysname = nullptr; static char sysname[512]; if(!psysname){ struct utsname sysinfo; diff --git a/src/string_util.cpp b/src/string_util.cpp index a1ab4cd..7e2e8b0 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -124,7 +124,7 @@ std::string trim(std::string s, const char *t /* = SPACES */) return trim_left(trim_right(std::move(s), t), t); } -std::string peeloff(std::string s) +std::string peeloff(const std::string& s) { if(s.size() < 2 || *s.begin() != '"' || *s.rbegin() != '"'){ return s; diff --git a/src/string_util.h b/src/string_util.h index 2577d49..077f5a6 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -79,7 +79,7 @@ std::string trim_left(std::string s, const char *t = SPACES); std::string trim_right(std::string s, const char *t = SPACES); std::string trim(std::string s, const char *t = SPACES); std::string lower(std::string s); -std::string peeloff(std::string s); +std::string peeloff(const std::string& s); // // Date string diff --git a/src/test_curl_util.cpp b/src/test_curl_util.cpp index ecd6fa9..1261728 100644 --- a/src/test_curl_util.cpp +++ b/src/test_curl_util.cpp @@ -54,7 +54,7 @@ const std::string& S3fsCred::GetBucket() #define ASSERT_IS_SORTED(x) assert_is_sorted((x), __FILE__, __LINE__) -void assert_is_sorted(struct curl_slist* list, const char *file, int line) +void assert_is_sorted(const struct curl_slist* list, const char *file, int line) { for(; list != nullptr; list = list->next){ std::string key1 = list->data;