Skip to content

Commit

Permalink
Added .clang-tidy file and fixed many cling-tidy warnigns (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianReimold authored Feb 3, 2023
1 parent dc2d1a6 commit 550e502
Show file tree
Hide file tree
Showing 17 changed files with 275 additions and 222 deletions.
62 changes: 62 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
# Resons why specific warnings have been turned off:
#
# -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
# This warns about memcpy and wants us to use memcpy_s, which is not available in our gcc setup.
#
# -cppcoreguidelines-pro-type-vararg
# This forbids using functions like printf, snprintf etc. We would like to use those either way.
#
# -misc-no-recursion
# Recursion with functions can be an elegant way of solving recursive problems
#
# These checks have been disabled to keep compatibility with C++14:
# -modernize-concat-nested-namespaces
# -modernize-use-nodiscard
#

Checks: "-*,
clang-analyzer-*,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-narrowing-conversions,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-pro-type-reinterpret-cast,
misc-*,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
modernize-*,
-modernize-pass-by-value,
-modernize-use-trailing-return-type,
-modernize-use-auto,
-modernize-concat-nested-namespaces,
-modernize-return-braced-init-list,
-modernize-use-nodiscard,
-modernize-avoid-bind,
performance-*,
readability-*,
-readability-braces-around-statements,
-readability-identifier-length,
-readability-magic-numbers,
-readability-redundant-access-specifiers,
-readability-function-cognitive-complexity,
-readability-else-after-return,
"
WarningsAsErrors: ''
HeaderFilterRegex: '^((?!/thirdparty/|/_deps/).)*$'
FormatStyle: none
2 changes: 1 addition & 1 deletion CMakeWindows.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mkdir _build
cd _build

cmake .. -DCMAKE_INSTALL_PREFIX=_install
cmake .. -DCMAKE_INSTALL_PREFIX=_install -DBUILD_SHARED_LIBS=OFF
cd ..
pause
1 change: 1 addition & 0 deletions fineftp-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(sources
src/server_impl.cpp
src/server_impl.h
src/user_database.cpp
src/user_database.h
src/win_str_convert.cpp
src/win_str_convert.h
)
Expand Down
16 changes: 8 additions & 8 deletions fineftp-server/include/fineftp/permissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace fineftp
None = 0
};

inline Permission operator~ (Permission a) { return (Permission)~(int)a; }
inline Permission operator| (Permission a, Permission b) { return (Permission)((int)a | (int)b); }
inline Permission operator& (Permission a, Permission b) { return (Permission)((int)a & (int)b); }
inline Permission operator^ (Permission a, Permission b) { return (Permission)((int)a ^ (int)b); }
inline Permission& operator|= (Permission& a, Permission b) { return (Permission&)((int&)a |= (int)b); }
inline Permission& operator&= (Permission& a, Permission b) { return (Permission&)((int&)a &= (int)b); }
inline Permission& operator^= (Permission& a, Permission b) { return (Permission&)((int&)a ^= (int)b); }
inline Permission operator~ (Permission a) { return static_cast<Permission>(~static_cast<int>(a)); }
inline Permission operator| (Permission a, Permission b) { return static_cast<Permission>(static_cast<int>(a) | static_cast<int>(b)); }
inline Permission operator& (Permission a, Permission b) { return static_cast<Permission>(static_cast<int>(a) & static_cast<int>(b)); }
inline Permission operator^ (Permission a, Permission b) { return static_cast<Permission>(static_cast<int>(a) ^ static_cast<int>(b)); }
inline Permission& operator|= (Permission& a, Permission b) { return reinterpret_cast<Permission&>(reinterpret_cast<int&>(a) |= static_cast<int>(b)); }
inline Permission& operator&= (Permission& a, Permission b) { return reinterpret_cast<Permission&>(reinterpret_cast<int&>(a) &= static_cast<int>(b)); }
inline Permission& operator^= (Permission& a, Permission b) { return reinterpret_cast<Permission&>(reinterpret_cast<int&>(a) ^= static_cast<int>(b)); }

}
}
17 changes: 11 additions & 6 deletions fineftp-server/include/fineftp/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ namespace fineftp
*/
FINEFTP_EXPORT FtpServer(uint16_t port = 21);

// Move
FINEFTP_EXPORT FtpServer(FtpServer&&) noexcept;
FINEFTP_EXPORT FtpServer& operator=(FtpServer&&) noexcept;

// Non-copyable
FtpServer(const FtpServer&) = delete;
FtpServer& operator=(const FtpServer&) = delete;

// Destructor
FINEFTP_EXPORT ~FtpServer();

/**
Expand All @@ -93,7 +102,7 @@ namespace fineftp
*
* @return True if adding the user was successful (i.e. it didn't exit already).
*/
FINEFTP_EXPORT bool addUser(const std::string& username, const std::string& password, const std::string& local_root_path, const Permission permissions);
FINEFTP_EXPORT bool addUser(const std::string& username, const std::string& password, const std::string& local_root_path, Permission permissions);

/**
* @brief Adds the "anonymous" / "ftp" user that FTP clients use to access FTP servers without password
Expand All @@ -103,7 +112,7 @@ namespace fineftp
*
* @return True if adding the anonymous user was successful (i.e. it didn't exit already).
*/
FINEFTP_EXPORT bool addUserAnonymous(const std::string& local_root_path, const Permission permissions);
FINEFTP_EXPORT bool addUserAnonymous(const std::string& local_root_path, Permission permissions);

/**
* @brief Starts the FTP Server
Expand Down Expand Up @@ -148,10 +157,6 @@ namespace fineftp
*/
FINEFTP_EXPORT std::string getAddress() const;

// Non-copyable
FINEFTP_EXPORT FtpServer(const FtpServer&) = delete;
FINEFTP_EXPORT FtpServer& operator=(const FtpServer&) = delete;

private:
std::unique_ptr<FtpServerImpl> ftp_server_; /**< Implementation details */
};
Expand Down
Loading

0 comments on commit 550e502

Please sign in to comment.