Tencent / rapidjson

A fast JSON parser/generator for C++ with both SAX/DOM style API
http://rapidjson.org/
Other
14.24k stars 3.54k forks source link

Some cppcheck warnings #1189

Open Adriatic1 opened 6 years ago

Adriatic1 commented 6 years ago

A list of cppcheck warnings generated on the latest code. Most of these might be inconsequential, but some are worth exploring (adding explicit declaration to constructors, operator precedence at the end).

[ext/rapidjson/encodings.h:277] -> [ext/rapidjson/encodings.h:271]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/encodings.h:293] -> [ext/rapidjson/encodings.h:271]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/encodings.h:308] -> [ext/rapidjson/encodings.h:271]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/encodings.h:326] -> [ext/rapidjson/encodings.h:271]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/encodings.h:327] -> [ext/rapidjson/encodings.h:326]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/encodings.h:426] -> [ext/rapidjson/encodings.h:420]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/encodings.h:433] -> [ext/rapidjson/encodings.h:420]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/encodings.h:440] -> [ext/rapidjson/encodings.h:420]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/encodings.h:448] -> [ext/rapidjson/encodings.h:420]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/internal/meta.h:108] -> [ext/rapidjson/internal/meta.h:107]: (style, inconclusive) The typedef 'StaticAssertTypedefLINE' hides a typedef with the same name. [ext/rapidjson/reader.h:930] -> [ext/rapidjson/reader.h:541]: (style, inconclusive) The typedef 'Ch' hides a typedef with the same name. [ext/rapidjson/reader.h:1401] -> [ext/rapidjson/reader.h:541]: (style, inconclusive) The typedef 'Ch' hides a typedef with the same name. [ext/rapidjson/reader.h:208] -> [ext/crypt/Sha256.h:15]: (style, inconclusive) The variable 'Int64' hides a typedef with the same name. [ext/rapidjson/document.h:2429] -> [ext/crypt/Sha256.h:15]: (style, inconclusive) The variable 'Int64' hides a typedef with the same name. [ext/rapidjson/writer.h:187] -> [ext/crypt/Sha256.h:15]: (style, inconclusive) The variable 'Int64' hides a typedef with the same name. [ext/rapidjson/document.h:1454]: (warning) Assert statement calls a function which may have desired side effects: 'MemberBegin'. [ext/rapidjson/document.h:1454]: (warning) Assert statement calls a function which may have desired side effects: 'MemberEnd'. [ext/rapidjson/document.h:1491]: (warning) Assert statement calls a function which may have desired side effects: 'MemberBegin'. [ext/rapidjson/document.h:1493]: (warning) Assert statement calls a function which may have desired side effects: 'MemberEnd'. [ext/rapidjson/document.h:1696]: (warning) Assert statement calls a function which may have desired side effects: 'Begin'. [ext/rapidjson/document.h:1698]: (warning) Assert statement calls a function which may have desired side effects: 'End'. [ext/rapidjson/reader.h:233]: (warning) Member variable 'StreamLocalCopy::s' is not initialized in the constructor. [ext/rapidjson/stream.h:161]: (performance, inconclusive) Technically the member function 'rapidjson::GenericStringStream::Tell' can be static. [ext/rapidjson/stream.h:196]: (performance, inconclusive) Technically the member function 'rapidjson::GenericInsituStringStream::Tell' can be static. [ext/rapidjson/stream.h:199]: (performance, inconclusive) Technically the member function 'rapidjson::GenericInsituStringStream::Put' can be static. [ext/rapidjson/stream.h:202]: (performance, inconclusive) Technically the member function 'rapidjson::GenericInsituStringStream::PutEnd' can be static. [ext/rapidjson/stream.h:203]: (performance, inconclusive) Technically the member function 'rapidjson::GenericInsituStringStream::Flush' can be static. [ext/rapidjson/stream.h:206]: (performance, inconclusive) Technically the member function 'rapidjson::GenericInsituStringStream::Pop' can be static. [ext/rapidjson/memorystream.h:50]: (performance, inconclusive) Technically the member function 'rapidjson::MemoryStream::Put' can be static. [ext/rapidjson/memorystream.h:51]: (performance, inconclusive) Technically the member function 'rapidjson::MemoryStream::Flush' can be static. [ext/rapidjson/memorystream.h:52]: (performance, inconclusive) Technically the member function 'rapidjson::MemoryStream::PutEnd' can be static. [ext/rapidjson/encodedstream.h:161]: (performance, inconclusive) Technically the member function 'rapidjson::AutoUTFInputStream::Put' can be static. [ext/rapidjson/encodedstream.h:162]: (performance, inconclusive) Technically the member function 'rapidjson::AutoUTFInputStream::Flush' can be static. [ext/rapidjson/encodedstream.h:164]: (performance, inconclusive) Technically the member function 'rapidjson::AutoUTFInputStream::PutEnd' can be static. [ext/rapidjson/encodedstream.h:264]: (performance, inconclusive) Technically the member function 'rapidjson::AutoUTFOutputStream::Peek' can be static. [ext/rapidjson/encodedstream.h:265]: (performance, inconclusive) Technically the member function 'rapidjson::AutoUTFOutputStream::Take' can be static. [ext/rapidjson/encodedstream.h:266]: (performance, inconclusive) Technically the member function 'rapidjson::AutoUTFOutputStream::Tell' can be static. [ext/rapidjson/encodedstream.h:268]: (performance, inconclusive) Technically the member function 'rapidjson::AutoUTFOutputStream::PutEnd' can be static. [ext/rapidjson/encodedstream.h:274]: (style, inconclusive) Technically the member function 'rapidjson::AutoUTFOutputStream::PutBOM' can be const. [ext/rapidjson/reader.h:203]: (performance, inconclusive) Technically the member function 'rapidjson::BaseReaderHandler::Default' can be static. [ext/rapidjson/reader.h:1724]: (performance, inconclusive) Technically the member function 'rapidjson::GenericReader::ParseValue' can be static. [ext/rapidjson/reader.h:1789]: (performance, inconclusive) Technically the member function 'rapidjson::GenericReader::Tokenize' can be static. [ext/rapidjson/reader.h:1816]: (performance, inconclusive) Technically the member function 'rapidjson::GenericReader::Predict' can be static. [ext/rapidjson/reader.h:2155]: (performance, inconclusive) Technically the member function 'rapidjson::GenericReader::IsIterativeParsingDelimiterState' can be static. [ext/rapidjson/reader.h:2159]: (performance, inconclusive) Technically the member function 'rapidjson::GenericReader::IsIterativeParsingCompleteState' can be static. [ext/rapidjson/document.h:332]: (performance, inconclusive) Technically the member function 'rapidjson::GenericStringRef::NotNullStrLen' can be static. [ext/rapidjson/document.h:1095]: (style, inconclusive) Technically the member function 'rapidjson::GenericValue::operator[]' can be const. [ext/rapidjson/document.h:1953]: (performance, inconclusive) Technically the member function 'rapidjson::GenericValue::ShortString::SetLength' can be static. [ext/rapidjson/document.h:1954]: (performance, inconclusive) Technically the member function 'rapidjson::GenericValue::ShortString::GetLength' can be static. [ext/rapidjson/document.h:2520]: (performance, inconclusive) Technically the member function 'rapidjson::GenericArray::Size' can be static. [ext/rapidjson/document.h:2521]: (performance, inconclusive) Technically the member function 'rapidjson::GenericArray::Capacity' can be static. [ext/rapidjson/document.h:2522]: (performance, inconclusive) Technically the member function 'rapidjson::GenericArray::Empty' can be static. [ext/rapidjson/document.h:2523]: (performance, inconclusive) Technically the member function 'rapidjson::GenericArray::Clear' can be static. [ext/rapidjson/document.h:2575]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::MemberCount' can be static. [ext/rapidjson/document.h:2576]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::MemberCapacity' can be static. [ext/rapidjson/document.h:2577]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::ObjectEmpty' can be static. [ext/rapidjson/document.h:2583]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::MemberBegin' can be static. [ext/rapidjson/document.h:2584]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::MemberEnd' can be static. [ext/rapidjson/document.h:2586]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::HasMember' can be static. [ext/rapidjson/document.h:2588]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::HasMember' can be static. [ext/rapidjson/document.h:2590]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::HasMember' can be static. [ext/rapidjson/document.h:2591]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::FindMember' can be static. [ext/rapidjson/document.h:2592]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::FindMember' can be static. [ext/rapidjson/document.h:2594]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::FindMember' can be static. [ext/rapidjson/document.h:2611]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::RemoveAllMembers' can be static. [ext/rapidjson/document.h:2612]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::RemoveMember' can be static. [ext/rapidjson/document.h:2614]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::RemoveMember' can be static. [ext/rapidjson/document.h:2616]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::RemoveMember' can be static. [ext/rapidjson/document.h:2617]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::RemoveMember' can be static. [ext/rapidjson/document.h:2618]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::EraseMember' can be static. [ext/rapidjson/document.h:2619]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::EraseMember' can be static. [ext/rapidjson/document.h:2620]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::EraseMember' can be static. [ext/rapidjson/document.h:2624]: (performance, inconclusive) Technically the member function 'rapidjson::GenericObject::EraseMember' can be static. [ext/rapidjson/stringbuffer.h:58]: (performance, inconclusive) Technically the member function 'rapidjson::GenericStringBuffer::Flush' can be static. [ext/rapidjson/writer.h:452]: (performance, inconclusive) Technically the member function 'rapidjson::Writer::ScanWriteUnescapedString' can be static. [ext/rapidjson/stream.h:122]: (style) Class 'GenericStreamWrapper' has a constructor with 1 argument that is not explicit. [ext/rapidjson/stream.h:157]: (style) Struct 'GenericStringStream' has a constructor with 1 argument that is not explicit. [ext/rapidjson/stream.h:191]: (style) Struct 'GenericInsituStringStream' has a constructor with 1 argument that is not explicit. [ext/rapidjson/encodedstream.h:44]: (style) Class 'EncodedInputStream' has a constructor with 1 argument that is not explicit. [ext/rapidjson/internal/ieee754.h:26]: (style) Class 'Double' has a constructor with 1 argument that is not explicit. [ext/rapidjson/internal/ieee754.h:27]: (style) Class 'Double' has a constructor with 1 argument that is not explicit. [ext/rapidjson/reader.h:233]: (style) Class 'StreamLocalCopy' has a constructor with 1 argument that is not explicit. [ext/rapidjson/reader.h:248]: (style) Class 'StreamLocalCopy' has a constructor with 1 argument that is not explicit. [ext/rapidjson/reader.h:932]: (style) Class 'StackStream' has a constructor with 1 argument that is not explicit. [ext/rapidjson/document.h:284]: (style) Struct 'GenericStringRef' has a constructor with 1 argument that is not explicit. [ext/rapidjson/document.h:760]: (style) Class 'GenericValue' has a constructor with 1 argument that is not explicit. [ext/rapidjson/document.h:771]: (style) Class 'GenericValue' has a constructor with 1 argument that is not explicit. [ext/rapidjson/document.h:2545]: (style) Class 'GenericArray' has a constructor with 1 argument that is not explicit. [ext/rapidjson/document.h:2633]: (style) Class 'GenericObject' has a constructor with 1 argument that is not explicit. [ext/rapidjson/writer.h:290]: (style) Struct 'Level' has a constructor with 1 argument that is not explicit. [ext/rapidjson/reader.h:1052]: (style) Clarify calculation precedence for '&' and '?'.

Adriatic1 commented 6 years ago

Additional issues by PvsStudio: /build/notecase_pro-4.3.5/ext/rapidjson/document.h 946 err V590 Consider inspecting the 'a >= b && a <= b' expression. The expression is excessive or contains a misprint. /build/notecase_pro-4.3.5/ext/rapidjson/document.h 1049 err V590 Consider inspecting the 'a >= b && a <= b' expression. The expression is excessive or contains a misprint. /build/notecase_pro-4.3.5/ext/rapidjson/internal/itoa.h 212 err V547 Expression 'value >= kTen8' is always true.

Adriatic1 commented 6 years ago

Two issues by g++ 7.2 ("-Wswitch-enum" flag):

./src/sync/../../ext/rapidjson/reader.h:1986:9: warning: enumeration value 'IterativeParsingFinishState' not handled in switch [-Wswitch-enum] switch (dst) { ^~

./src/sync/../../ext/rapidjson/reader.h:2141:9: warning: enumeration value 'IterativeParsingErrorState' not handled in switch [-Wswitch-enum] switch (src) {

Adriatic1 commented 6 years ago

Few more g++ 5.4.0 issues: ./src/sync/../../ext/rapidjson/internal/biginteger.h: In member function 'rapidjson::internal::BigInteger& rapidjson::internal::BigInteger::MultiplyPow5(unsigned int)': ./src/sync/../../ext/rapidjson/internal/biginteger.h:179:80: warning: useless cast to type 'uint32_t {aka unsigned int}' [-Wuseless-cast] for (; exp >= 13; exp -= 13) this = static_cast(1220703125u); // 5^13 ^ ./src/sync/../../ext/rapidjson/document.h: In instantiation of 'bool rapidjson::GenericValue<Encoding, Allocator>::Accept(Handler&) const [with Handler = rapidjson::Writer<rapidjson::GenericStringBuffer<rapidjson::UTF8<> > >; Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>]': ./src/sync/../../ext/rapidjson/document.h:1847:9: warning: enumeration value 'kNumberType' not handled in switch [-Wswitch-enum] switch(GetType()) { ^