diff --git a/CHANGELOG.md b/CHANGELOG.md index 22f33c9d..206cbd50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ HEAD * Fixed support for `volatile float` and `volatile double` (issue #1557) * Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560) * Fixed `serializeJson(doc, String)` when allocation fails (issue #1572) +* Fixed clang-tidy warnings (issue #1574, PR #1577 by @armandas) v6.18.0 (2021-05-05) ------- diff --git a/README.md b/README.md index c3002843..090d5549 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) * [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) * [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) + * Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/) * Well documented * [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme) * [Examples](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) diff --git a/extras/tests/.clang-tidy b/extras/tests/.clang-tidy new file mode 100644 index 00000000..579ae587 --- /dev/null +++ b/extras/tests/.clang-tidy @@ -0,0 +1 @@ +Checks: '-clang-analyzer-security.insecureAPI.*' diff --git a/src/ArduinoJson/Document/JsonDocument.hpp b/src/ArduinoJson/Document/JsonDocument.hpp index d67d9349..64c76b8f 100644 --- a/src/ArduinoJson/Document/JsonDocument.hpp +++ b/src/ArduinoJson/Document/JsonDocument.hpp @@ -32,7 +32,7 @@ class JsonDocument : public Visitable { void clear() { _pool.clear(); - _data.setNull(); + _data.init(); } template @@ -304,15 +304,15 @@ class JsonDocument : public Visitable { protected: JsonDocument() : _pool(0, 0) { - _data.setNull(); + _data.init(); } JsonDocument(MemoryPool pool) : _pool(pool) { - _data.setNull(); + _data.init(); } JsonDocument(char* buf, size_t capa) : _pool(buf, capa) { - _data.setNull(); + _data.init(); } ~JsonDocument() {} diff --git a/src/ArduinoJson/Json/Latch.hpp b/src/ArduinoJson/Json/Latch.hpp index aef1fe36..70866d6b 100644 --- a/src/ArduinoJson/Json/Latch.hpp +++ b/src/ArduinoJson/Json/Latch.hpp @@ -45,7 +45,8 @@ class Latch { } TReader _reader; - char _current; + char _current; // NOLINT(clang-analyzer-optin.cplusplus.UninitializedObject) + // Not initialized in constructor (+10 bytes on AVR) bool _loaded; #if ARDUINOJSON_DEBUG bool _ended; diff --git a/src/ArduinoJson/Json/TextFormatter.hpp b/src/ArduinoJson/Json/TextFormatter.hpp index 18694f14..7795671f 100644 --- a/src/ArduinoJson/Json/TextFormatter.hpp +++ b/src/ArduinoJson/Json/TextFormatter.hpp @@ -155,7 +155,6 @@ class TextFormatter { protected: CountingDecorator _writer; - size_t _length; private: TextFormatter &operator=(const TextFormatter &); // cannot be assigned diff --git a/src/ArduinoJson/Json/Utf16.hpp b/src/ArduinoJson/Json/Utf16.hpp index 4e2750f3..00397caf 100644 --- a/src/ArduinoJson/Json/Utf16.hpp +++ b/src/ArduinoJson/Json/Utf16.hpp @@ -31,7 +31,7 @@ inline bool isLowSurrogate(uint16_t codeunit) { class Codepoint { public: - Codepoint() : _highSurrogate(0) {} + Codepoint() : _highSurrogate(0), _codepoint(0) {} bool append(uint16_t codeunit) { if (isHighSurrogate(codeunit)) { diff --git a/src/ArduinoJson/Memory/MemoryPool.hpp b/src/ArduinoJson/Memory/MemoryPool.hpp index 49debf85..c8262186 100644 --- a/src/ArduinoJson/Memory/MemoryPool.hpp +++ b/src/ArduinoJson/Memory/MemoryPool.hpp @@ -37,7 +37,8 @@ class MemoryPool { } void* buffer() { - return _begin; + return _begin; // NOLINT(clang-analyzer-unix.Malloc) + // movePointers() alters this pointer } // Gets the capacity of the memoryPool in bytes diff --git a/src/ArduinoJson/StringStorage/StringCopier.hpp b/src/ArduinoJson/StringStorage/StringCopier.hpp index 8b1104b4..80670aad 100644 --- a/src/ArduinoJson/StringStorage/StringCopier.hpp +++ b/src/ArduinoJson/StringStorage/StringCopier.hpp @@ -55,8 +55,12 @@ class StringCopier { private: MemoryPool* _pool; + + // These fields aren't initialized by the constructor but startString() + // + // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) char* _ptr; - size_t _size; - size_t _capacity; + // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) + size_t _size, _capacity; }; } // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Variant/VariantData.hpp b/src/ArduinoJson/Variant/VariantData.hpp index 82ae745d..5631147f 100644 --- a/src/ArduinoJson/Variant/VariantData.hpp +++ b/src/ArduinoJson/Variant/VariantData.hpp @@ -33,7 +33,7 @@ class VariantData { // - no virtual // - no inheritance void init() { - _flags = 0; + _flags = VALUE_IS_NULL; } template