From bbfa91141ad0e2fee9ff3ce2c4b94af8d95d43c9 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Mon, 11 Feb 2019 18:41:01 -0800 Subject: [PATCH] Configure clang-tidy target Also fix nits. --- .clang-tidy | 4 ++++ src/Makefile.am | 15 +++++++++++++-- src/curl.cpp | 2 +- src/s3fs.cpp | 6 +++--- src/string_util.cpp | 20 ++++++++++---------- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 20098a6..28143de 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,7 @@ Checks: ' -*, bugprone-*, + -bugprone-macro-parentheses, google-*, -google-build-using-namespace, -google-readability-casting, @@ -12,6 +13,7 @@ Checks: ' -misc-redundant-expression, -misc-unused-parameters, modernize-*, + -modernize-avoid-c-arrays, -modernize-deprecated-headers, -modernize-loop-convert, -modernize-use-auto, @@ -22,5 +24,7 @@ Checks: ' readability-*, -readability-else-after-return, -readability-implicit-bool-conversion, + -readability-isolate-declaration, + -readability-magic-numbers, -readability-named-parameter, -readability-simplify-boolean-expr' diff --git a/src/Makefile.am b/src/Makefile.am index f102c42..5b230dd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,7 +24,15 @@ if USE_GNUTLS_NETTLE AM_CPPFLAGS += -DUSE_GNUTLS_NETTLE endif -s3fs_SOURCES = s3fs.cpp s3fs.h curl.cpp curl.h cache.cpp cache.h string_util.cpp string_util.h s3fs_util.cpp s3fs_util.h fdcache.cpp fdcache.h common_auth.cpp s3fs_auth.h addhead.cpp addhead.h common.h +s3fs_SOURCES = \ + s3fs.cpp \ + curl.cpp \ + cache.cpp \ + string_util.cpp \ + s3fs_util.cpp \ + fdcache.cpp \ + common_auth.cpp \ + addhead.cpp if USE_SSL_OPENSSL s3fs_SOURCES += openssl_auth.cpp endif @@ -39,6 +47,9 @@ s3fs_LDADD = $(DEPS_LIBS) noinst_PROGRAMS = test_string_util -test_string_util_SOURCES = string_util.cpp test_string_util.cpp test_util.h +test_string_util_SOURCES = string_util.cpp test_string_util.cpp TESTS = test_string_util + +clang-tidy: + clang-tidy $(s3fs_SOURCES) -- $(DEPS_CFLAGS) $(CPPFLAGS) diff --git a/src/curl.cpp b/src/curl.cpp index 8960293..3bb91d3 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -3853,7 +3853,7 @@ int S3fsCurl::MultipartHeadRequest(const char* tpath, off_t size, headers_t& met strrange.str(""); strrange.clear(stringstream::goodbit); - if(0 != (result = CopyMultipartPostSetup(tpath, tpath, (list.size() + 1), upload_id, meta))){ + if(0 != (result = CopyMultipartPostSetup(tpath, tpath, static_cast(list.size() + 1), upload_id, meta))){ return result; } list.push_back(partdata.etag); diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 13e4a16..e85e1bf 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -937,7 +937,7 @@ static int s3fs_readlink(const char* _path, char* buf, size_t size) if(use_wtf8){ strTmp = s3fs_wtf8_decode(strTmp); } - strcpy(buf, strTmp.c_str()); + strncpy(buf, strTmp.c_str(), size); FdManager::get()->Close(ent); S3FS_MALLOCTRIM(0); @@ -973,7 +973,7 @@ static int do_create_bucket() headers_t meta; S3fsCurl s3fscurl(true); - long res = s3fscurl.PutRequest("/", meta, tmpfd); + int res = s3fscurl.PutRequest("/", meta, tmpfd); if(res < 0){ long responseCode = s3fscurl.GetLastResponseCode(); if((responseCode == 400 || responseCode == 403) && S3fsCurl::IsSignatureV4()){ @@ -4555,7 +4555,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar return 0; } if(0 == STR2NCMP(arg, "multireq_max=")){ - long maxreq = static_cast(s3fs_strtoofft(strchr(arg, '=') + sizeof(char))); + int maxreq = static_cast(s3fs_strtoofft(strchr(arg, '=') + sizeof(char))); S3fsCurl::SetMaxMultiRequest(maxreq); return 0; } diff --git a/src/string_util.cpp b/src/string_util.cpp index 95190a5..5b19ecb 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -96,7 +96,7 @@ off_t s3fs_strtoofft(const char* str, bool is_base_16) string lower(string s) { // change each character of the string to lower case - for(unsigned int i = 0; i < s.length(); i++){ + for(size_t i = 0; i < s.length(); i++){ s[i] = tolower(s[i]); } return s; @@ -132,7 +132,7 @@ string trim(const string &s, const string &t /* = SPACES */) string urlEncode(const string &s) { string result; - for (unsigned i = 0; i < s.length(); ++i) { + for (size_t i = 0; i < s.length(); ++i) { char c = s[i]; if (c == '/' // Note- special case for fuse paths... || c == '.' @@ -160,7 +160,7 @@ string urlEncode(const string &s) string urlEncode2(const string &s) { string result; - for (unsigned i = 0; i < s.length(); ++i) { + for (size_t i = 0; i < s.length(); ++i) { char c = s[i]; if (c == '=' // Note- special case for fuse paths... || c == '&' // Note- special case for s3... @@ -185,11 +185,11 @@ string urlEncode2(const string &s) string urlDecode(const string& s) { string result; - for(unsigned i = 0; i < s.length(); ++i){ + for(size_t i = 0; i < s.length(); ++i){ if(s[i] != '%'){ result += s[i]; }else{ - char ch = 0; + int ch = 0; if(s.length() <= ++i){ break; // wrong format. } @@ -199,7 +199,7 @@ string urlDecode(const string& s) } ch *= 16; ch += ('0' <= s[i] && s[i] <= '9') ? (s[i] - '0') : ('A' <= s[i] && s[i] <= 'F') ? (s[i] - 'A' + 0x0a) : ('a' <= s[i] && s[i] <= 'f') ? (s[i] - 'a' + 0x0a) : 0x00; - result += ch; + result += static_cast(ch); } } return result; @@ -525,9 +525,9 @@ bool s3fs_wtf8_encode(const char *s, string *result) invalid = true; if (result) { unsigned escape = escape_base + c; - *result += 0xe0 | ((escape >> 12) & 0x0f); - *result += 0x80 | ((escape >> 06) & 0x3f); - *result += 0x80 | ((escape >> 00) & 0x3f); + *result += static_cast(0xe0 | ((escape >> 12) & 0x0f)); + *result += static_cast(0x80 | ((escape >> 06) & 0x3f)); + *result += static_cast(0x80 | ((escape >> 00) & 0x3f)); } } return invalid; @@ -556,7 +556,7 @@ bool s3fs_wtf8_decode(const char *s, string *result) // convert back encoded = true; if(result){ - *result += code - escape_base; + *result += static_cast(code - escape_base); } s+=2; continue;