Skip to content

some static analysis warning at line 11317 #1390

Closed

Description

@sssnaplab
  • What is the issue you have?
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?

arm-linux-gnueabihf-g++ (Linaro GCC 6.3-2017.05) 6.3.1 20170404
  • Did you use a released version of the library or the version from the develop branch?
version: 3.4.0 from develop branch 

Activity

  1. nlohmann commented on Dec 12, 2018

    @nlohmann
    Owner

    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?

  2. added
    solution: wontfixthe issue will not be fixed (either it is impossible or deemed out of scope)
    on Dec 20, 2018
  3. mgerhardy commented on May 8, 2020

    @mgerhardy

    This is not just static analysis - the compiler prints this, too. A proper fix is attached at #755

        template<typename NumberType, detail::enable_if_t<
                     std::is_same<NumberType, number_unsigned_t>::value, int> = 0>
        bool is_negative_integer(NumberType x) { return false; }
    
        template<typename NumberType, detail::enable_if_t<
                     std::is_same<NumberType, number_integer_t>::value, int> = 0>
        bool is_negative_integer(NumberType x) { return x<0; }
    

    and in dump_integer(NumberType x):
    const bool is_negative = is_negative_integer(x); // see issue #755

  4. mgerhardy commented on May 8, 2020

    @mgerhardy

    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 us

  5. t-b commented on May 8, 2020

    @t-b
    Contributor

    @mgerhardy Can you provide a PR?

  6. darkdragon-001 commented on Oct 23, 2020

    @darkdragon-001

    This was fixed in c61a907.

  7. linked a pull request that will close this issueAdd build step for NVCC and fix a warning #3227on Dec 29, 2021
  8. added
    solution: proposed fixa fix for the issue has been proposed and waits for confirmation
    and removed
    solution: wontfixthe issue will not be fixed (either it is impossible or deemed out of scope)
    on Dec 30, 2021
  9. self-assigned this
    on Dec 30, 2021
  10. added this to the Release 3.10.5 milestone on Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址