Fix -Wtautological-constant-out-of-range-compare warnings on 32-bit systems #19735

pull hebasto wants to merge 2 commits into bitcoin:master from hebasto:200816-size changing 3 files +6 −5
  1. hebasto commented at 9:38 am on August 16, 2020: member

    On 32-bit system

    0$ uname -nrmo
    1odroid-hc1 4.14.187-odroidxu4 armv7l GNU/Linux
    2$ lsb_release -ds
    3Ubuntu 20.04.1 LTS
    4$ clang --version
    5clang version 10.0.0-4ubuntu1 
    6Target: armv7l-unknown-linux-gnueabihf
    7Thread model: posix
    8InstalledDir: /usr/bin
    

    the clang fires the following warnings:

     0  CXX      policy/libbitcoin_common_a-feerate.o
     1policy/feerate.cpp:14:20: warning: result of comparison of constant 9223372036854775807 with expression of type 'size_t' (aka 'unsigned int') is always true [-Wtautological-constant-out-of-range-compare]
     2    assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
     3           ~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     4/usr/include/assert.h:93:27: note: expanded from macro 'assert'
     5     (static_cast <bool> (expr)                                         \
     6                          ^~~~
     7policy/feerate.cpp:25:20: warning: result of comparison of constant 9223372036854775807 with expression of type 'size_t' (aka 'unsigned int') is always true [-Wtautological-constant-out-of-range-compare]
     8    assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
     9           ~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    10/usr/include/assert.h:93:27: note: expanded from macro 'assert'
    11     (static_cast <bool> (expr)                                         \
    12                          ^~~~
    132 warnings generated.
    

    Fix is safe as https://github.com/bitcoin/bitcoin/blob/a57af897ec16976b28de05aa0b9c3f6a96d73ede/src/compat/assumptions.h#L55-L59

  2. DrahtBot added the label TX fees and policy on Aug 16, 2020
  3. practicalswift commented at 4:29 pm on August 16, 2020: contributor

    Concept ACK

    Please consider enabling -Wtautological-constant-out-of-range-compare too :)

  4. hebasto commented at 4:39 pm on August 16, 2020: member

    Please consider enabling -Wtautological-constant-out-of-range-compare too :)

    Isn’t it enabled by default? https://clang.llvm.org/docs/DiagnosticsReference.html#wtautological-constant-out-of-range-compare

  5. theStack commented at 7:59 pm on September 6, 2020: member
    Code Review ACK 7c30e9f6f2f18057366383cb2b0a54d99731041c
  6. DrahtBot commented at 6:09 am on November 29, 2020: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #21848 (refactor: Make CFeeRate constructor architecture-independent by MarcoFalke)

    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.

  7. in src/policy/feerate.cpp:23 in 7c30e9f6f2 outdated
    18@@ -20,7 +19,6 @@ CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
    19 
    20 CAmount CFeeRate::GetFee(size_t nBytes_) const
    21 {
    22-    assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
    


    MarcoFalke commented at 10:27 am on May 4, 2021:
    How is this assert save to remove for 64-bit?

    hebasto commented at 11:52 am on May 7, 2021:

    Oh, my bad!

    Thanks! Updated.

  8. hebasto force-pushed on May 7, 2021
  9. hebasto commented at 11:51 am on May 7, 2021: member

    Updated 7c30e9f6f2f18057366383cb2b0a54d99731041c -> 3759a5b3be7a88f265a282388af603b27e458ec0 (pr19735.01 -> pr19735.02):

  10. Fix -Wtautological-constant-out-of-range-compare warnings on 32-bit
    It is safe, see assumptions.h:
    "We assume size_t to be 32-bit or 64-bit."
    c092473d92
  11. Drop redundant `static_assert`s
    It is safe, see assumptions.h:
    "We assume size_t to be 32-bit or 64-bit."
    65ea9aae3d
  12. hebasto force-pushed on May 7, 2021
  13. DrahtBot commented at 9:40 am on May 24, 2021: member

    🐙 This pull request conflicts with the target branch and needs rebase.

    Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a “draft”.

  14. DrahtBot added the label Needs rebase on May 24, 2021
  15. hebasto commented at 10:31 am on May 24, 2021: member
    The problem has been resolved in #21848 :tiger2:
  16. hebasto closed this on May 24, 2021

  17. hebasto deleted the branch on May 24, 2021
  18. fanquake removed the label Needs rebase on May 31, 2021
  19. DrahtBot locked this on Aug 18, 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: 2024-09-29 04:12 UTC

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