gui: fix compiler warning in formatPingTime() #18252

pull vasild wants to merge 1 commits into bitcoin:master from vasild:implicit-change-formatPingTime changing 1 files +4 −1
  1. vasild commented at 12:55 PM on March 3, 2020: member

    With Clang 10.0.0:

    qt/guiutil.cpp:778:26: warning: implicit conversion from 'std::__1::numeric_limits<long>::type'
          (aka 'long') to 'double' changes value from 9223372036854775807 to 9223372036854775808
          [-Wimplicit-int-float-conversion]
        return (dPingTime == std::numeric_limits<int64_t>::max()/1e6 || dPingTime == 0) ? QObject::...
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    When assigning to dPingTime a similar typecast is used:

    src/net.cpp:558:    stats.dPingTime = (((double)nPingUsecTime) / 1e6);
    

    so it should be ok to change 9223372036854775807 to 9223372036854775808.

    <!-- *** Please remove the following help text before submitting: *** Pull requests without a rationale and clear improvement may be closed immediately. -->

    <!-- Please provide clear motivation for your patch and explain how it improves Bitcoin Core user experience or Bitcoin Core developer experience significantly: * Any test improvements or new tests that improve coverage are always welcome. * All other changes should have accompanying unit tests (see `src/test/`) or functional tests (see `test/`). Contributors should note which tests cover modified code. If no tests exist for a region of modified code, new tests should accompany the change. * Bug fixes are most welcome when they come with steps to reproduce or an explanation of the potential issue as well as reasoning for the way the bug was fixed. * Features are welcome, but might be rejected due to design or scope issues. If a feature is based on a lot of dependencies, contributors should first consider building the system outside of Bitcoin Core, if possible. * Refactoring changes are only accepted if they are required for a feature or bug fix or otherwise improve developer experience significantly. For example, most "code style" refactoring changes require a thorough explanation why they are useful, what downsides they have and why they *significantly* improve developer experience or avoid serious programming bugs. Note that code style is often a subjective matter. Unless they are explicitly mentioned to be preferred in the [developer notes](/doc/developer-notes.md), stylistic code changes are usually rejected. -->

    <!-- Bitcoin Core has a thorough review process and even the most trivial change needs to pass a lot of eyes and requires non-zero or even substantial time effort to review. There is a huge lack of active reviewers on the project, so patches often sit for a long time. -->

  2. build: fix compiler warning in formatPingTime()
    With Clang 10.0.0:
    
    ```
    qt/guiutil.cpp:778:26: warning: implicit conversion from 'std::__1::numeric_limits<long>::type'
          (aka 'long') to 'double' changes value from 9223372036854775807 to 9223372036854775808
          [-Wimplicit-int-float-conversion]
        return (dPingTime == std::numeric_limits<int64_t>::max()/1e6 || dPingTime == 0) ? QObject::...
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ```
    
    When assigning to `dPingTime` a similar typecast is used:
    
    ```
    src/net.cpp:558:    stats.dPingTime = (((double)nPingUsecTime) / 1e6);
    ```
    
    so it should be ok to change 9223372036854775807 to 9223372036854775808.
    d0b9f6e287
  3. fanquake added the label GUI on Mar 3, 2020
  4. Empact commented at 1:47 PM on March 3, 2020: member

    Here's a proposed alternative - representing these values as int64_t internally, and only converting to double at the time of display. Motivated by a general distrust of floating point and a desire to minimize the points at which it's used: https://github.com/bitcoin/bitcoin/compare/master...Empact:2020-03-ping-time

  5. MarcoFalke renamed this:
    build: fix compiler warning in formatPingTime()
    gui: fix compiler warning in formatPingTime()
    on Mar 3, 2020
  6. practicalswift commented at 3:21 PM on March 3, 2020: contributor

    Concept ACK on fixing but I prefer @Empact's approach :)

  7. promag commented at 11:43 AM on March 4, 2020: member

    From a quick look and comparison I also prefer @Empact approach.

  8. Empact commented at 6:54 PM on March 4, 2020: member

    Opened the alternative as #18260

  9. DrahtBot commented at 8:10 PM on March 4, 2020: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #18260 (refactor: Fix implicit value conversion in formatPingTime by Empact)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  10. fanquake commented at 12:10 AM on March 5, 2020: member

    Given the comments here, I'm going to close this in favour of #18260.

  11. fanquake closed this on Mar 5, 2020

  12. vasild deleted the branch on Mar 5, 2020
  13. vasild commented at 5:02 PM on March 5, 2020: member

    Excellent! Yes, #18260 clearly supersedes this PR.

  14. MarcoFalke referenced this in commit aaf09469fb on Mar 5, 2020
  15. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me