clang-tidy: add checking headers and fix warnings 79/311879/4
authorKrzysztof Malysa <k.malysa@samsung.com>
Wed, 29 May 2024 11:35:06 +0000 (13:35 +0200)
committerKrzysztof Malysa <k.malysa@samsung.com>
Tue, 4 Jun 2024 15:15:08 +0000 (17:15 +0200)
Change-Id: I2f6e36c0ee967b580261201cd548695c966fc2ed

run-clang-tidy.sh
srcs/crypto/encryptor.cpp
srcs/crypto/noise/noise.h
srcs/lowercase_hex_string_of.h
srcs/message.h
srcs/request_handler.h
srcs/tunnel.cpp
srcs/tunnel.h
srcs/websockets.cpp
srcs/websockets.h
tests/ctap_message_processor_tests.cpp

index ae85cb620dd610f372d83bd88cbf323073d10c01..66f9d0c99202ebd4885e01f799a22f474678edac 100755 (executable)
@@ -18,7 +18,9 @@ fi
 # Update compile commands in case it is outdated
 ./generate_compile_commands.sh
 
+HEADER_FILES_REGEX="$(find srcs tests | grep '\.h$' | grep -v '/tinycbor/' | tr '\n' '|' | sed 's%|$%%')"
+
 find srcs tests |
     grep -P '\.(h|c|cpp)$' |
     grep -v /tinycbor/ |
-    parallel "echo {}; ${CLANG_TIDY} -p . \"{}\""
+    parallel --bar "echo {}; ${CLANG_TIDY} -header-filter='${HEADER_FILES_REGEX}' -p . \"{}\""
index 50817a4b4419688ab569f50bb8056da3ea091928..199594bef702695d5fd665bebd8114ce6fd95949 100644 (file)
@@ -160,7 +160,7 @@ CryptoBuffer DecryptAes256GCM(const CryptoBuffer &key,
 
     EVP_CIPHER_CTX *ctx = nullptr;
     int len = 0;
-    size_t outputLen = 0;
+    [[maybe_unused]] size_t outputLen = 0;
     CryptoBuffer output(ciphertext.size() - TAG_LEN);
 
     ctx = EVP_CIPHER_CTX_new();
index 0afcfb2acc17b69ce8441d477eaf897737bf5db4..e8e138d3c7efcba4a2bf91cc3b26f90b62ef1081 100644 (file)
@@ -44,7 +44,7 @@ public:
 
     CryptoBuffer DecryptAndHash(const CryptoBuffer &ciphertext);
 
-    CryptoBuffer GetHandshakeHash() const;
+    [[nodiscard]] CryptoBuffer GetHandshakeHash() const;
 
     class CipherState {
     public:
@@ -54,7 +54,7 @@ public:
 
         CryptoBuffer DecryptWithAd(const CryptoBuffer &ciphertext, const CryptoBuffer &ad);
 
-        const CryptoBuffer &Key() const { return m_key; }
+        [[nodiscard]] const CryptoBuffer &Key() const { return m_key; }
 
     private:
         friend class SymmetricState;
@@ -70,7 +70,7 @@ public:
         CipherState second;
     };
 
-    SplitRes Split() const;
+    [[nodiscard]] SplitRes Split() const;
 
 private:
     CryptoBuffer m_chainingKey;
index 6a6f06f27fb19276fc099292c9017a096e8b8e9a..82e6801758475c663c2b062fb2640aa34da5b6b0 100644 (file)
@@ -24,7 +24,7 @@ std::string LowercaseHexStringOf(const Bytes &bytes)
 {
     static_assert(sizeof(typename Bytes::value_type) == 1);
     std::string res;
-    for (uint8_t byte : bytes) {
+    for (const uint8_t byte : bytes) {
         constexpr char digits[] = "0123456789abcdef";
         res += digits[byte >> 4];
         res += digits[byte & 15];
index 3d4d489773fb9ec79104820c7c32290bad3ec1fc..4eca4adb336b3c291ab745650f8feb82acf41dba 100644 (file)
@@ -211,7 +211,7 @@ public:
         Buffer m_handshakeSignature;
     };
 
-    const std::optional<LinkData> &GetLinkData() const noexcept { return m_linkData; }
+    [[nodiscard]] const std::optional<LinkData> &GetLinkData() const noexcept { return m_linkData; }
 
 private:
     std::optional<LinkData> m_linkData;
index fa2b1015bed2e98de4ba9f305950576a2f7fe6a1..67f8dae059537bf9d590dcf2e0555bd4b1cc5cfa 100644 (file)
@@ -337,6 +337,7 @@ private:
                     THROW_UNKNOWN("Unexpected transport: " << transport);
             }
 
+            // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
             auto &attestationData = forCallbacks.ctapResponse.m_authData.m_attestationData.value();
 
             Assign(forCallbacks.response.subject_pubkey_info,
index 61cefab06e63fcd1aa84b1955c876bec8d7899ca..52f965df018337dc996fcf6cfd30ef289971505d 100644 (file)
@@ -85,16 +85,7 @@ const std::unordered_map<enum lws_close_status, std::string> CLOSE_STATUS2STR =
 
 } // namespace
 
-Tunnel::Tunnel(std::shared_ptr<IWebsockets> ws)
-: m_ws(std::move(ws)),
-  m_context(nullptr),
-  m_connection(nullptr),
-  m_writtenBytesNum(0),
-  m_state(State::DISCONNECTED),
-  m_cancelled(false)
-{
-    m_ws->SetListener(this);
-}
+Tunnel::Tunnel(std::shared_ptr<IWebsockets> ws) : m_ws(std::move(ws)) { m_ws->SetListener(this); }
 
 Tunnel::~Tunnel()
 {
index 7a32c6b8db82e72f541abe1eb6b33a04cbfbf738..996d538e4495a332b1fb04b61e523b8f695ddaa4 100644 (file)
@@ -93,15 +93,15 @@ protected:
     void DisconnectOnError();
 
     std::shared_ptr<IWebsockets> m_ws;
-    LwsContext *m_context;
-    Lws *m_connection;
+    LwsContext *m_context = nullptr;
+    Lws *m_connection = nullptr;
     std::optional<ExtraHttpHeader> m_extraHttpHeader;
     std::vector<uint8_t> m_in;
     std::vector<uint8_t> m_out;
     std::deque<std::vector<uint8_t>> m_recvMsgs;
-    size_t m_writtenBytesNum;
-    State m_state;
-    bool m_cancelled;
+    size_t m_writtenBytesNum = 0;
+    State m_state = State::DISCONNECTED;
+    bool m_cancelled = false;
 
     /*
      * Protects m_cancelled and m_context.
index 05730fa61578a28f7d2e844023337c0eac2a8509..04f7a2d0ed989e6a1bcb20c70adcfdf34fa312ea 100644 (file)
@@ -55,10 +55,6 @@ bool RedirectWebsocketsLogs() noexcept
 } // namespace
 
 Websockets::Websockets() noexcept
-: m_protocols{
-      {"fido.cable", FidoCallback, 0, RX_BUFFER_SIZE, 0, this, 0},
-      LWS_PROTOCOL_LIST_TERM
-}
 {
     [[maybe_unused]] static const bool redirected = RedirectWebsocketsLogs();
 }
index e9f343d2e53441531b87b1a5c307e89ee3925eff..4b80b76af6450b57810353f70fd8d91c1d497e89 100644 (file)
@@ -219,5 +219,8 @@ private:
                             void *in,
                             size_t len) noexcept;
 
-    const struct lws_protocols m_protocols[2];
+    const struct lws_protocols m_protocols[2] = {
+        {"fido.cable", FidoCallback, 0, RX_BUFFER_SIZE, 0, this, 0},
+        LWS_PROTOCOL_LIST_TERM,
+    };
 };
index cd918e3306bf775012b8bc9826731a08743ae0bb..99dce00b183e630e9380f4beaed654563e172528 100644 (file)
@@ -63,7 +63,10 @@ public:
         throw std::runtime_error{""};
     }
 
-    const std::vector<CryptoBuffer> &WrittenMessages() const noexcept { return m_writtenMessages; }
+    [[nodiscard]] const std::vector<CryptoBuffer> &WrittenMessages() const noexcept
+    {
+        return m_writtenMessages;
+    }
 
 private:
     std::vector<CryptoBuffer> m_messagesToRead;