Skip to content

gcc compile warnings #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xiaoyur347 opened this issue Nov 17, 2014 · 1 comment
Closed

gcc compile warnings #77

xiaoyur347 opened this issue Nov 17, 2014 · 1 comment

Comments

@xiaoyur347
Copy link
Contributor

My gcc compiler flags are as follows:
-Wall -Wextra -Wno-unused-result
And compile the latest source code of jsoncpp, and get the following warnings:
[ 33%] Building CXX object json_reader.cpp.o
json_reader.cpp: In member function ‘bool Json::Reader::pushError(const Json::Value&, const string&)’:
json_reader.cpp:834:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
json_reader.cpp:835:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
json_reader.cpp: In member function ‘bool Json::Reader::pushError(const Json::Value&, const string&, const Json::Value&)’:
json_reader.cpp:850:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
json_reader.cpp:851:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
json_reader.cpp:852:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
[ 66%] Building CXX object json_value.cpp.o
json_value.cpp: In copy constructor ‘Json::Value::CZString::CZString(const Json::Value::CZString&)’:
json_value.cpp:179:26: warning: enumeral and non-enumeral type in conditional expression [enabled by default]

PATCH

src/lib_json/json_reader.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp
index 1b2f187..c5111f8 100644
--- a/src/lib_json/json_reader.cpp
+++ b/src/lib_json/json_reader.cpp
@@ -831,8 +831,9 @@ std::vectorReader::StructuredError Reader::getStructuredErrors() const {
}

bool Reader::pushError(const Value& value, const std::string& message) {

  • if(value.getOffsetStart() > end_ - begin_
  • || value.getOffsetLimit() > end_ - begin_)
  • size_t length = end_ - begin_;
  • if(value.getOffsetStart() > length
  • || value.getOffsetLimit() > length)
    return false;
    Token token;
    token.type_ = tokenError;
    @@ -847,9 +848,10 @@ bool Reader::pushError(const Value& value, const std::string& message) {
    }

bool Reader::pushError(const Value& value, const std::string& message, const Value& extra) {

  • if(value.getOffsetStart() > end_ - begin_
  • || value.getOffsetLimit() > end_ - begin_
  • || extra.getOffsetLimit() > end_ - begin_)
  • size_t length = end_ - begin_;
  • if(value.getOffsetStart() > length
  • || value.getOffsetLimit() > length
  • || extra.getOffsetLimit() > length)
    return false;
    Token token;
    token.type_ = tokenError;

src/lib_json/json_value.cpp | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp
index b6ea8ff..b4af62b 100644
--- a/src/lib_json/json_value.cpp
+++ b/src/lib_json/json_value.cpp
@@ -170,13 +170,17 @@ Value::CZString::CZString(const char* cstr, DuplicationPolicy allocate)
: cstr_(allocate == duplicate ? duplicateStringValue(cstr) : cstr),
index_(allocate) {}

-Value::CZString::CZString(const CZString& other)

  • : cstr_(other.index_ != noDuplication && other.cstr_ != 0
  •            ? duplicateStringValue(other.cstr_)
    
  •            : other.cstr_),
    
  •  index_(other.cstr_
    
  •             ? (other.index_ == noDuplication ? noDuplication : duplicate)
    
  •             : other.index_) {}
    
    +Value::CZString::CZString(const CZString& other) {
  • DuplicationPolicy policy = static_cast(other.index_);
  • if (policy != noDuplication && other.cstr_ != 0)
  • cstr_ = duplicateStringValue(other.cstr_);
  • else
  •  cstr_ = other.cstr_;
    
  • if (other.cstr_)
  • index_ = (policy == noDuplication ? noDuplication : duplicate);
  • else
  • index_ = other.index_;
    +}

Value::CZString::~CZString() {
if (cstr_ && index_ == duplicate)

@cdunn2001
Copy link
Contributor

Thanks for noticing this. Can you submit this as an actual Github Pull Request?

ya1gaurav added a commit to ya1gaurav/jsoncpp that referenced this issue Nov 17, 2014
Submitting Patch for Issue : open-source-parsers#77
It will fix warnings in json_reader.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants