You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Firstly, thanks for making this great easy json utility!
I'm not sure this is false positive or something, but I just report this warning.
May this be helpful~
at line 11317 in json.hpp
const bool is_negative = std::is_same<NumberType, number_integer_t>::value and not (x >= 0); // see issue #755
static analysis tool says (codesonar),
Redundant Condition
x >= 0 always evaluates to true.
The condition is testing whether an unsigned value is nonnegative, but unsigned values are always nonnegative.
Please describe the steps to reproduce the issue. Can you provide a small but working code example?
What is the expected behavior?
And what is the actual behavior instead?
Which compiler and operating system are you using? Is it a supported compiler?
The function is templated for integer types. For signed integers, the line can become false, whereas it is always true for unsigned integer types. To "fix" this issue, I would need to artificially make two functions from it and remove some code from the unsigned version. Therefore, I would classify this as false positive. What do you think?
Activity
nlohmann commentedon Dec 12, 2018
The function is templated for integer types. For signed integers, the line can become
false, whereas it is always true for unsigned integer types. To "fix" this issue, I would need to artificially make two functions from it and remove some code from the unsigned version. Therefore, I would classify this as false positive. What do you think?mgerhardy commentedon May 8, 2020
This is not just static analysis - the compiler prints this, too. A proper fix is attached at #755
and in dump_integer(NumberType x):
const bool is_negative = is_negative_integer(x); // see issue #755mgerhardy commentedon May 8, 2020
oh.. the compiler that reports this as a warning is clang-10 btw. and as we are compiling with
-Werror- this is a problem for ust-b commentedon May 8, 2020
@mgerhardy Can you provide a PR?
darkdragon-001 commentedon Oct 23, 2020
This was fixed in c61a907.