Skip to content

Clang Analyzer warning - null pointer passed as an argument #404

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
Jesse-V opened this issue Jan 18, 2016 · 1 comment
Closed

Clang Analyzer warning - null pointer passed as an argument #404

Jesse-V opened this issue Jan 18, 2016 · 1 comment

Comments

@Jesse-V
Copy link

Jesse-V commented Jan 18, 2016

jsoncpp/jsoncpp.cpp:2629:14: warning: Null pointer passed as an argument to a 'nonnull' parameter
int comp = memcmp(this->cstr_, other.cstr_, this_len);
_________^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

I'm using Fedora 23, Clang 3.7 and the 1.6.5 release of jsoncpp. The line in question occurs in the "bool Value::CZString::operator==(const CZString& other) const" method. It's not obvious to me which argument is null, but there does seem to be an existence check for cstr_, so it must be either "other.cstr_" or "this_len". This could also be a false positive, but it's probably worth investigating.

@cdunn2001
Copy link
Contributor

We did some tricks to add a feature while maintaining binary compatibility. I'm pretty sure that any 2 CZStrings compared with each other will always be either both cstr or both index. Maybe we could shut up the compiler with an assertion?

ya1gaurav added a commit to ya1gaurav/jsoncpp that referenced this issue Mar 1, 2016
As per discussion in - open-source-parsers#404
Null should not be pass to memcmp, it may show undesired behaviour, so avoid doing that using assertion.
Also, changed one direct "assert" to JSON_ASSERT - it will be decided if exceptions are used or not.
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