From 65e4aef2a1764f3a6fc26c1789acc29409296bd0 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 1 Dec 2024 10:29:08 +0900 Subject: [PATCH] Prefer C++-style casts over C-style casts (#2599) The former are easier to identify. Found via clang-tidy. Co-authored-by: Takeshi Nakatani --- .clang-tidy | 1 - src/curl.cpp | 4 ++-- src/s3fs.cpp | 10 +++++----- test/truncate_read_file.cc | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a2ab729..fbc57e6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -37,7 +37,6 @@ Checks: ' -cppcoreguidelines-special-member-functions, -fuchsia-*, -google-build-using-namespace, - -google-readability-casting, -google-readability-function-size, -google-readability-todo, -google-runtime-int, diff --git a/src/curl.cpp b/src/curl.cpp index 6ff8fe3..8ab7580 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -499,7 +499,7 @@ size_t S3fsCurl::UploadReadCallback(void* ptr, size_t size, size_t nmemb, void* return 0; } // read size - ssize_t copysize = (size * nmemb) < (size_t)pCurl->partdata.size ? (size * nmemb) : (size_t)pCurl->partdata.size; + ssize_t copysize = (size * nmemb) < static_cast(pCurl->partdata.size) ? (size * nmemb) : static_cast(pCurl->partdata.size); ssize_t readbytes; ssize_t totalread; // read and set @@ -537,7 +537,7 @@ size_t S3fsCurl::DownloadWriteCallback(void* ptr, size_t size, size_t nmemb, voi } // write size - ssize_t copysize = (size * nmemb) < (size_t)pCurl->partdata.size ? (size * nmemb) : (size_t)pCurl->partdata.size; + ssize_t copysize = (size * nmemb) < static_cast(pCurl->partdata.size) ? (size * nmemb) : static_cast(pCurl->partdata.size); ssize_t writebytes; ssize_t totalwrite; diff --git a/src/s3fs.cpp b/src/s3fs.cpp index b1f2e3f..c851e7f 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -2039,10 +2039,10 @@ static int s3fs_chown(const char* _path, uid_t uid, gid_t gid) return result; } - if((uid_t)(-1) == uid){ + if(static_cast(-1) == uid){ uid = stbuf.st_uid; } - if((gid_t)(-1) == gid){ + if(static_cast(-1) == gid){ gid = stbuf.st_gid; } if(S_ISDIR(stbuf.st_mode)){ @@ -2161,10 +2161,10 @@ static int s3fs_chown_nocopy(const char* _path, uid_t uid, gid_t gid) return result; } - if((uid_t)(-1) == uid){ + if(static_cast(-1) == uid){ uid = stbuf.st_uid; } - if((gid_t)(-1) == gid){ + if(static_cast(-1) == gid){ gid = stbuf.st_gid; } @@ -2749,7 +2749,7 @@ static int s3fs_open(const char* _path, struct fuse_file_info* fi) FdEntity* ent; headers_t meta; - if((unsigned int)fi->flags & O_TRUNC){ + if(static_cast(fi->flags) & O_TRUNC){ if(0 != st.st_size){ st.st_size = 0; needs_flush = true; diff --git a/test/truncate_read_file.cc b/test/truncate_read_file.cc index 015a1b7..9fbdb78 100644 --- a/test/truncate_read_file.cc +++ b/test/truncate_read_file.cc @@ -51,7 +51,7 @@ int main(int argc, const char *argv[]) // truncate if(0 != ftruncate(fd, size)){ - fprintf(stderr, "[ERROR] Could not truncate file(%s) to %lld byte.\n", filepath, (long long)size); + fprintf(stderr, "[ERROR] Could not truncate file(%s) to %lld byte.\n", filepath, static_cast(size)); close(fd); exit(EXIT_FAILURE); }