Skip to content

Commit

Permalink
clang-tidy C++ (#1308)
Browse files Browse the repository at this point in the history
modernize clang-tidy and fix tasks.py command
  • Loading branch information
jmillan committed Jan 9, 2024
1 parent e485eaa commit c6517f8
Show file tree
Hide file tree
Showing 28 changed files with 116 additions and 1,830 deletions.
9 changes: 8 additions & 1 deletion doc/Building.md
Expand Up @@ -200,8 +200,15 @@ Runs [clang-tidy](http://clang.llvm.org/extra/clang-tidy) and performs C++ code
- `invoke clean` and `invoke mediasoup-worker` must have been called first.
- [PyYAML](https://pyyaml.org) is required.
- In OSX install it with `brew install libyaml` and `sudo easy_install-X.Y pyyaml`.
- [clang-tools-extra](https://clang.llvm.org/extra/index.html) is required.
- In OSX install it with `brew install clang-tools-extra`.
- In linux the package name is `clang-tools-extra`.

"MEDIASOUP_TIDY_CHECKS" environment variable with a comma separated list of checks overrides the checks defined in `.clang-tidy` file.
**Environment variables**

- "MEDIASOUP_TIDY_CHECKS": comma separated list of checks. Overrides the checks defined in `.clang-tidy` file.
- "MEDIASOUP_TIDY_FILES": space separated source files to process, including their path. All .cpp files will be processes by default.
- "MEDIASOUP_CLANG_TIDY_DIR": path to directory containing clang tools (run-clang-tidy, clang-tidy, clang-apply-replacements).

### `invoke fuzzer`

Expand Down
12 changes: 10 additions & 2 deletions worker/.clang-tidy
@@ -1,21 +1,26 @@
---
Checks: "*,\
-altera*,\
-android*,\
-boost-use-to-string,\
-bugprone-easily-swappable-parameters,\
-bugprone-implicit-widening-of-multiplication-result,\
-bugprone-lambda-function-name,\
-bugprone-macro-parentheses,\
-bugprone-reserved-identifier,\
-cert-*,\
-clang-analyzer-optin.osx.*,\
-clang-analyzer-osx.*,\
-cppcoreguidelines-avoid-c-arrays,\
-cppcoreguidelines-avoid-do-while,\
-cppcoreguidelines-avoid-goto,\
-cppcoreguidelines-avoid-non-const-global-variables,\
-cppcoreguidelines-avoid-magic-numbers,\
-cppcoreguidelines-init-variables,\
-cppcoreguidelines-no-malloc,\
-cppcoreguidelines-non-private-member-variables-in-classes,\
-cppcoreguidelines-owning-memory,\
-cppcoreguidelines-prefer-member-initializer,\
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,\
-cppcoreguidelines-pro-bounds-constant-array-index,\
-cppcoreguidelines-pro-bounds-pointer-arithmetic,\
Expand All @@ -27,9 +32,11 @@ Checks: "*,\
-cppcoreguidelines-special-member-functions,\
-fuchsia-default-arguments-calls,\
-fuchsia-default-arguments-declarations,\
-fuchsia-overloaded-operator,\
-google-default-arguments,\
-google-readability-*,\
-google-runtime-references,\
-google-upgrade-googletest-case,\
-hicpp-avoid-c-arrays,\
-hicpp-avoid-goto,\
-hicpp-braces-around-statements,\
Expand All @@ -42,7 +49,9 @@ Checks: "*,\
-llvm-header-guard,\
-llvm-else-after-return,\
-llvmlibc-*,\
-misc-confusable-identifiers,\
-misc-non-private-member-variables-in-classes,\
-misc-use-anonymous-namespace,\
-modernize-avoid-c-arrays,\
-modernize-concat-nested-namespaces,\
-modernize-make-unique,\
Expand All @@ -59,7 +68,6 @@ Checks: "*,\
-readability-uppercase-literal-suffix,\
"

HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
User: mediasoup
FormatStyle: file
Expand Down Expand Up @@ -332,7 +340,7 @@ CheckOptions:
- key: readability-identifier-naming.UnionSuffix
value: ''
- key: readability-identifier-naming.ValueTemplateParameterCase
value: camelBack
value: CamelCase
- key: readability-identifier-naming.ValueTemplateParameterPrefix
value: ''
- key: readability-identifier-naming.ValueTemplateParameterSuffix
Expand Down
2 changes: 1 addition & 1 deletion worker/include/Channel/ChannelRequest.hpp
Expand Up @@ -53,7 +53,7 @@ namespace Channel
void TypeError(const char* reason = nullptr);

private:
void Send(uint8_t* buffer, size_t size);
void Send(uint8_t* buffer, size_t size) const;
void SendResponse(const flatbuffers::Offset<FBS::Response::Response>& response);

public:
Expand Down
3 changes: 1 addition & 2 deletions worker/include/RTC/RtpDictionaries.hpp
Expand Up @@ -210,8 +210,7 @@ namespace RTC
{
public:
RtpHeaderExtensionParameters() = default;
explicit RtpHeaderExtensionParameters(
const FBS::RtpParameters::RtpHeaderExtensionParameters* const data);
explicit RtpHeaderExtensionParameters(const FBS::RtpParameters::RtpHeaderExtensionParameters* data);

flatbuffers::Offset<FBS::RtpParameters::RtpHeaderExtensionParameters> FillBuffer(
flatbuffers::FlatBufferBuilder& builder) const;
Expand Down
14 changes: 7 additions & 7 deletions worker/include/RTC/SeqManager.hpp
Expand Up @@ -18,29 +18,29 @@ namespace RTC
public:
struct SeqLowerThan
{
bool operator()(const T lhs, const T rhs) const;
bool operator()(T lhs, T rhs) const;
};

struct SeqHigherThan
{
bool operator()(const T lhs, const T rhs) const;
bool operator()(T lhs, T rhs) const;
};

private:
static const SeqLowerThan isSeqLowerThan;
static const SeqHigherThan isSeqHigherThan;
static const SeqLowerThan isSeqLowerThan; // NOLINT(readability-identifier-naming)
static const SeqHigherThan isSeqHigherThan; // NOLINT(readability-identifier-naming)

public:
static bool IsSeqLowerThan(const T lhs, const T rhs);
static bool IsSeqHigherThan(const T lhs, const T rhs);
static bool IsSeqLowerThan(T lhs, T rhs);
static bool IsSeqHigherThan(T lhs, T rhs);

public:
SeqManager() = default;

public:
void Sync(T input);
void Drop(T input);
bool Input(const T input, T& output);
bool Input(T input, T& output);
T GetMaxInput() const;
T GetMaxOutput() const;

Expand Down
4 changes: 2 additions & 2 deletions worker/include/Settings.hpp
Expand Up @@ -55,8 +55,8 @@ class Settings
thread_local static struct Configuration configuration;

private:
static absl::flat_hash_map<std::string, LogLevel> string2LogLevel;
static absl::flat_hash_map<LogLevel, std::string> logLevel2String;
static absl::flat_hash_map<std::string, LogLevel> String2LogLevel; // NOLINT(readability-identifier-naming)
static absl::flat_hash_map<LogLevel, std::string> LogLevel2String; // NOLINT(readability-identifier-naming)
};

#endif
24 changes: 12 additions & 12 deletions worker/include/Utils.hpp
Expand Up @@ -57,9 +57,7 @@ namespace Utils
std::memcmp(
std::addressof(reinterpret_cast<const struct sockaddr_in6*>(addr1)->sin6_addr),
std::addressof(reinterpret_cast<const struct sockaddr_in6*>(addr2)->sin6_addr),
16) == 0
? true
: false);
16) == 0);
}

default:
Expand All @@ -71,7 +69,9 @@ namespace Utils

static struct sockaddr_storage CopyAddress(const struct sockaddr* addr)
{
struct sockaddr_storage copiedAddr;
struct sockaddr_storage copiedAddr
{
};

switch (addr->sa_family)
{
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace Utils
auto byte0 = data[i + 2]; // The less significant byte.

// Check bit 7 (sign).
uint8_t extension = byte2 & 0b10000000 ? 0b11111111 : 0b00000000;
const uint8_t extension = byte2 & 0b10000000 ? 0b11111111 : 0b00000000;

return int32_t{ byte0 } | (int32_t{ byte1 } << 8) | (int32_t{ byte2 } << 16) |
(int32_t{ extension } << 24);
Expand Down Expand Up @@ -252,10 +252,10 @@ namespace Utils
return (((Crypto::seed >> 4) & 0x7FFF7FFF) % (max - min + 1)) + min;
}

static const std::string GetRandomString(size_t len)
static std::string GetRandomString(size_t len)
{
char buffer[64];
static const char chars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
static const char Chars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };

Expand All @@ -266,10 +266,10 @@ namespace Utils

for (size_t i{ 0 }; i < len; ++i)
{
buffer[i] = chars[GetRandomUInt(0, sizeof(chars) - 1)];
buffer[i] = Chars[GetRandomUInt(0, sizeof(Chars) - 1)];
}

return std::string(buffer, len);
return { buffer, len };
}

static uint32_t GetCRC32(const uint8_t* data, size_t size)
Expand All @@ -279,7 +279,7 @@ namespace Utils

while (size--)
{
crc = Crypto::crc32Table[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
crc = Crypto::Crc32Table[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
}

return crc ^ ~0U;
Expand All @@ -292,7 +292,7 @@ namespace Utils
thread_local static EVP_MAC* mac;
thread_local static EVP_MAC_CTX* hmacSha1Ctx;
thread_local static uint8_t hmacSha1Buffer[];
static const uint32_t crc32Table[256];
static const uint32_t Crc32Table[256];
};

class String
Expand Down Expand Up @@ -328,7 +328,7 @@ namespace Utils

static Time::Ntp TimeMs2Ntp(uint64_t ms)
{
Time::Ntp ntp; // NOLINT(cppcoreguidelines-pro-type-member-init)
Time::Ntp ntp{}; // NOLINT(cppcoreguidelines-pro-type-member-init)

ntp.seconds = ms / 1000;
ntp.fractions =
Expand Down
2 changes: 1 addition & 1 deletion worker/include/Worker.hpp
Expand Up @@ -30,7 +30,7 @@ class Worker : public Channel::ChannelSocket::Listener,
RTC::WebRtcServer* GetWebRtcServer(const std::string& webRtcServerId) const;
RTC::Router* GetRouter(const std::string& routerId) const;
void CheckNoWebRtcServer(const std::string& webRtcServerId) const;
void CheckNoRouter(const std::string& webRtcServerId) const;
void CheckNoRouter(const std::string& routerId) const;

/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
Expand Down
2 changes: 2 additions & 0 deletions worker/include/handles/UdpSocketHandle.hpp
Expand Up @@ -84,8 +84,10 @@ class UdpSocketHandle

/* Callbacks fired by UV events. */
public:
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
void OnUvRecvAlloc(size_t suggestedSize, uv_buf_t* buf);
void OnUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags);
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
void OnUvSend(int status, UdpSocketHandle::onSendCallback* cb);

/* Pure virtual methods that must be implemented by the subclass. */
Expand Down

0 comments on commit c6517f8

Please sign in to comment.