Skip to content

Commit dc76c51

Browse files
committed
Fixed clang-tidy warnings (fixes #1574)
2 parents e32a855 + de11b36 commit dc76c51

File tree

10 files changed

+19
-11
lines changed

10 files changed

+19
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ HEAD
77
* Fixed support for `volatile float` and `volatile double` (issue #1557)
88
* Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560)
99
* Fixed `serializeJson(doc, String)` when allocation fails (issue #1572)
10+
* Fixed clang-tidy warnings (issue #1574, PR #1577 by @armandas)
1011

1112
v6.18.0 (2021-05-05)
1213
-------

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
8181
* [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)
8282
* [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)
8383
* [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
84+
* Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/)
8485
* Well documented
8586
* [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme)
8687
* [Examples](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)

extras/tests/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Checks: '-clang-analyzer-security.insecureAPI.*'

src/ArduinoJson/Document/JsonDocument.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class JsonDocument : public Visitable {
3232

3333
void clear() {
3434
_pool.clear();
35-
_data.setNull();
35+
_data.init();
3636
}
3737

3838
template <typename T>
@@ -304,15 +304,15 @@ class JsonDocument : public Visitable {
304304

305305
protected:
306306
JsonDocument() : _pool(0, 0) {
307-
_data.setNull();
307+
_data.init();
308308
}
309309

310310
JsonDocument(MemoryPool pool) : _pool(pool) {
311-
_data.setNull();
311+
_data.init();
312312
}
313313

314314
JsonDocument(char* buf, size_t capa) : _pool(buf, capa) {
315-
_data.setNull();
315+
_data.init();
316316
}
317317

318318
~JsonDocument() {}

src/ArduinoJson/Json/Latch.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class Latch {
4545
}
4646

4747
TReader _reader;
48-
char _current;
48+
char _current; // NOLINT(clang-analyzer-optin.cplusplus.UninitializedObject)
49+
// Not initialized in constructor (+10 bytes on AVR)
4950
bool _loaded;
5051
#if ARDUINOJSON_DEBUG
5152
bool _ended;

src/ArduinoJson/Json/TextFormatter.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ class TextFormatter {
155155

156156
protected:
157157
CountingDecorator<TWriter> _writer;
158-
size_t _length;
159158

160159
private:
161160
TextFormatter &operator=(const TextFormatter &); // cannot be assigned

src/ArduinoJson/Json/Utf16.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ inline bool isLowSurrogate(uint16_t codeunit) {
3131

3232
class Codepoint {
3333
public:
34-
Codepoint() : _highSurrogate(0) {}
34+
Codepoint() : _highSurrogate(0), _codepoint(0) {}
3535

3636
bool append(uint16_t codeunit) {
3737
if (isHighSurrogate(codeunit)) {

src/ArduinoJson/Memory/MemoryPool.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class MemoryPool {
3737
}
3838

3939
void* buffer() {
40-
return _begin;
40+
return _begin; // NOLINT(clang-analyzer-unix.Malloc)
41+
// movePointers() alters this pointer
4142
}
4243

4344
// Gets the capacity of the memoryPool in bytes

src/ArduinoJson/StringStorage/StringCopier.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ class StringCopier {
5555

5656
private:
5757
MemoryPool* _pool;
58+
59+
// These fields aren't initialized by the constructor but startString()
60+
//
61+
// NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject)
5862
char* _ptr;
59-
size_t _size;
60-
size_t _capacity;
63+
// NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject)
64+
size_t _size, _capacity;
6165
};
6266
} // namespace ARDUINOJSON_NAMESPACE

src/ArduinoJson/Variant/VariantData.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class VariantData {
3333
// - no virtual
3434
// - no inheritance
3535
void init() {
36-
_flags = 0;
36+
_flags = VALUE_IS_NULL;
3737
}
3838

3939
template <typename TVisitor>

0 commit comments

Comments
 (0)