* PVS Studio fix

http://oracle.fly-server.ru/pvs-studio/jsoncpp/
This commit is contained in:
Pave Pimenov 2020-09-05 16:09:19 +03:00
parent 45733df96c
commit 32457a772e
5 changed files with 11 additions and 14 deletions

View File

@ -335,6 +335,7 @@ int main(int argc, const char* argv[]) {
std::cerr << "Unhandled exception:" << std::endl << e.what() << std::endl; std::cerr << "Unhandled exception:" << std::endl << e.what() << std::endl;
return 1; return 1;
} }
return 0;
} }
#if defined(__GNUC__) #if defined(__GNUC__)

View File

@ -52,7 +52,7 @@ template <typename T>
static std::unique_ptr<T> cloneUnique(const std::unique_ptr<T>& p) { static std::unique_ptr<T> cloneUnique(const std::unique_ptr<T>& p) {
std::unique_ptr<T> r; std::unique_ptr<T> r;
if (p) { if (p) {
r = std::unique_ptr<T>(new T(*p)); r = std::make_unique<T>(*p);
} }
return r; return r;
} }
@ -840,7 +840,6 @@ bool Value::isConvertibleTo(ValueType other) const {
(type() == realValue && InRange(value_.real_, 0, maxUInt)) || (type() == realValue && InRange(value_.real_, 0, maxUInt)) ||
type() == booleanValue || type() == nullValue; type() == booleanValue || type() == nullValue;
case realValue: case realValue:
return isNumeric() || type() == booleanValue || type() == nullValue;
case booleanValue: case booleanValue:
return isNumeric() || type() == booleanValue || type() == nullValue; return isNumeric() || type() == booleanValue || type() == nullValue;
case stringValue: case stringValue:
@ -1240,7 +1239,7 @@ Value::Members Value::getMemberNames() const {
ObjectValues::const_iterator it = value_.map_->begin(); ObjectValues::const_iterator it = value_.map_->begin();
ObjectValues::const_iterator itEnd = value_.map_->end(); ObjectValues::const_iterator itEnd = value_.map_->end();
for (; it != itEnd; ++it) { for (; it != itEnd; ++it) {
members.push_back(String((*it).first.data(), (*it).first.length())); members.emplace_back(String((*it).first.data(), (*it).first.length()));
} }
return members; return members;
} }
@ -1397,7 +1396,7 @@ String Value::Comments::get(CommentPlacement slot) const {
void Value::Comments::set(CommentPlacement slot, String comment) { void Value::Comments::set(CommentPlacement slot, String comment) {
if (!ptr_) { if (!ptr_) {
ptr_ = std::unique_ptr<Array>(new Array()); ptr_ = std::make_unique<Array>();
} }
// check comments array boundry. // check comments array boundry.
if (slot < CommentPlacement::numberOfCommentPlacement) { if (slot < CommentPlacement::numberOfCommentPlacement) {
@ -1549,7 +1548,7 @@ void Path::makePath(const String& path, const InArgs& in) {
const char* beginName = current; const char* beginName = current;
while (current != end && !strchr("[.", *current)) while (current != end && !strchr("[.", *current))
++current; ++current;
args_.push_back(String(beginName, current)); args_.emplace_back(String(beginName, current));
} }
} }
} }

View File

@ -68,7 +68,7 @@
#if !defined(isnan) #if !defined(isnan)
// IEEE standard states that NaN values will not compare to themselves // IEEE standard states that NaN values will not compare to themselves
#define isnan(x) (x != x) #define isnan(x) ((x) != (x))
#endif #endif
#if !defined(__APPLE__) #if !defined(__APPLE__)
@ -1168,9 +1168,7 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const {
const bool emitUTF8 = settings_["emitUTF8"].asBool(); const bool emitUTF8 = settings_["emitUTF8"].asBool();
unsigned int pre = settings_["precision"].asUInt(); unsigned int pre = settings_["precision"].asUInt();
CommentStyle::Enum cs = CommentStyle::All; CommentStyle::Enum cs = CommentStyle::All;
if (cs_str == "All") { if (cs_str == "None") {
cs = CommentStyle::All;
} else if (cs_str == "None") {
cs = CommentStyle::None; cs = CommentStyle::None;
} else { } else {
throwRuntimeError("commentStyle must be 'All' or 'None'"); throwRuntimeError("commentStyle must be 'All' or 'None'");

View File

@ -253,7 +253,7 @@ void Runner::runTestAt(size_t index, TestResult& result) const {
bool Runner::runAllTest(bool printSummary) const { bool Runner::runAllTest(bool printSummary) const {
size_t const count = testCount(); size_t const count = testCount();
std::deque<TestResult> failures; std::vector<TestResult> failures;
for (size_t index = 0; index < count; ++index) { for (size_t index = 0; index < count; ++index) {
TestResult result; TestResult result;
runTestAt(index, result); runTestAt(index, result);
@ -408,7 +408,7 @@ Json::String ToJsonString(const char* toConvert) {
return Json::String(toConvert); return Json::String(toConvert);
} }
Json::String ToJsonString(Json::String in) { return in; } Json::String ToJsonString(const Json::String& in) { return in; }
#if JSONCPP_USING_SECURE_MEMORY #if JSONCPP_USING_SECURE_MEMORY
Json::String ToJsonString(std::string in) { Json::String ToJsonString(std::string in) {

View File

@ -2732,12 +2732,11 @@ JSONTEST_FIXTURE_LOCAL(StreamWriterTest, escapeTabCharacterWindows) {
struct ReaderTest : JsonTest::TestCase { struct ReaderTest : JsonTest::TestCase {
void setStrictMode() { void setStrictMode() {
reader = std::unique_ptr<Json::Reader>( reader = std::make_unique<Json::Reader>(Json::Features{}.strictMode());
new Json::Reader(Json::Features{}.strictMode()));
} }
void setFeatures(Json::Features& features) { void setFeatures(Json::Features& features) {
reader = std::unique_ptr<Json::Reader>(new Json::Reader(features)); reader = std::make_unique<Json::Reader>(features);
} }
void checkStructuredErrors( void checkStructuredErrors(