From 8b7d80c63ae765bd65364697fc3a2595254b7af9 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sat, 9 Nov 2024 14:49:32 -0800 Subject: [PATCH] Prefer C++-style casts over C-style casts The former are easier to identify. Found via clang-tidy. --- .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 df11168..adb10bf 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -615,7 +615,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 @@ -653,7 +653,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 17326c2..e02a251 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -2088,10 +2088,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)){ @@ -2210,10 +2210,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; } @@ -2798,7 +2798,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); }