Fixed clang-tidy warnings (fixes #1574)

This commit is contained in:
Benoit Blanchon
2021-06-04 11:39:19 +02:00
10 changed files with 19 additions and 11 deletions

View File

@@ -7,6 +7,7 @@ HEAD
* Fixed support for `volatile float` and `volatile double` (issue #1557) * Fixed support for `volatile float` and `volatile double` (issue #1557)
* Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560) * Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560)
* Fixed `serializeJson(doc, String)` when allocation fails (issue #1572) * 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) v6.18.0 (2021-05-05)
------- -------

View File

@@ -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) * [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) * [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) * [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 * Well documented
* [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme) * [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) * [Examples](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)

1
extras/tests/.clang-tidy Normal file
View File

@@ -0,0 +1 @@
Checks: '-clang-analyzer-security.insecureAPI.*'

View File

@@ -32,7 +32,7 @@ class JsonDocument : public Visitable {
void clear() { void clear() {
_pool.clear(); _pool.clear();
_data.setNull(); _data.init();
} }
template <typename T> template <typename T>
@@ -304,15 +304,15 @@ class JsonDocument : public Visitable {
protected: protected:
JsonDocument() : _pool(0, 0) { JsonDocument() : _pool(0, 0) {
_data.setNull(); _data.init();
} }
JsonDocument(MemoryPool pool) : _pool(pool) { JsonDocument(MemoryPool pool) : _pool(pool) {
_data.setNull(); _data.init();
} }
JsonDocument(char* buf, size_t capa) : _pool(buf, capa) { JsonDocument(char* buf, size_t capa) : _pool(buf, capa) {
_data.setNull(); _data.init();
} }
~JsonDocument() {} ~JsonDocument() {}

View File

@@ -45,7 +45,8 @@ class Latch {
} }
TReader _reader; TReader _reader;
char _current; char _current; // NOLINT(clang-analyzer-optin.cplusplus.UninitializedObject)
// Not initialized in constructor (+10 bytes on AVR)
bool _loaded; bool _loaded;
#if ARDUINOJSON_DEBUG #if ARDUINOJSON_DEBUG
bool _ended; bool _ended;

View File

@@ -155,7 +155,6 @@ class TextFormatter {
protected: protected:
CountingDecorator<TWriter> _writer; CountingDecorator<TWriter> _writer;
size_t _length;
private: private:
TextFormatter &operator=(const TextFormatter &); // cannot be assigned TextFormatter &operator=(const TextFormatter &); // cannot be assigned

View File

@@ -31,7 +31,7 @@ inline bool isLowSurrogate(uint16_t codeunit) {
class Codepoint { class Codepoint {
public: public:
Codepoint() : _highSurrogate(0) {} Codepoint() : _highSurrogate(0), _codepoint(0) {}
bool append(uint16_t codeunit) { bool append(uint16_t codeunit) {
if (isHighSurrogate(codeunit)) { if (isHighSurrogate(codeunit)) {

View File

@@ -37,7 +37,8 @@ class MemoryPool {
} }
void* buffer() { void* buffer() {
return _begin; return _begin; // NOLINT(clang-analyzer-unix.Malloc)
// movePointers() alters this pointer
} }
// Gets the capacity of the memoryPool in bytes // Gets the capacity of the memoryPool in bytes

View File

@@ -55,8 +55,12 @@ class StringCopier {
private: private:
MemoryPool* _pool; MemoryPool* _pool;
// These fields aren't initialized by the constructor but startString()
//
// NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject)
char* _ptr; char* _ptr;
size_t _size; // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject)
size_t _capacity; size_t _size, _capacity;
}; };
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -33,7 +33,7 @@ class VariantData {
// - no virtual // - no virtual
// - no inheritance // - no inheritance
void init() { void init() {
_flags = 0; _flags = VALUE_IS_NULL;
} }
template <typename TVisitor> template <typename TVisitor>