Skip to content

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

Closed
hebasto wants to merge 2 commits into
bitcoin:masterfrom
hebasto:200816-size
Closed

hebasto wants to merge 2 commits into
bitcoin:masterfrom
hebasto:200816-size

Conversation

@hebasto

@hebasto hebasto commented Aug 16, 2020

Copy link
Copy Markdown
Member

On 32-bit system

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

the clang fires the following warnings:

  CXX      policy/libbitcoin_common_a-feerate.o
policy/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]
    assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
           ~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/assert.h:93:27: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
                          ^~~~
policy/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]
    assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
           ~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/assert.h:93:27: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
                          ^~~~
2 warnings generated.

Fix is safe as

// Assumption: We assume size_t to be 32-bit or 64-bit.
// Example(s): size_t assumed to be at least 32-bit in ecdsa_signature_parse_der_lax(...).
// size_t assumed to be 32-bit or 64-bit in MallocUsage(...).
static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, "size_t assumed to be 32-bit or 64-bit");
static_assert(sizeof(size_t) == sizeof(void*), "Sizes of size_t and void* assumed to be equal");

@practicalswift

practicalswift commented Aug 16, 2020 •

Copy link
Copy Markdown
Contributor

Concept ACK

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

@hebasto

hebasto commented Aug 16, 2020

Copy link
Copy Markdown
Member Author

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

@theStack

theStack commented Sep 6, 2020

Copy link
Copy Markdown
Contributor

Code Review ACK 7c30e9f

@DrahtBot

DrahtBot commented Nov 29, 2020 •

Copy link
Copy Markdown
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

Comment thread src/policy/feerate.cpp Resolved
@hebasto

hebasto commented May 7, 2021

Copy link
Copy Markdown
Member Author

Updated 7c30e9f -> 3759a5b (pr19735.01 -> pr19735.02):

hebasto added 2 commits May 7, 2021 17:55
It is safe, see assumptions.h:
"We assume size_t to be 32-bit or 64-bit."
It is safe, see assumptions.h:
"We assume size_t to be 32-bit or 64-bit."
@DrahtBot

Copy link
Copy Markdown
Contributor

🐙 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".

@hebasto

hebasto commented May 24, 2021

Copy link
Copy Markdown
Member Author

The problem has been resolved in #21848 🐅

@hebasto hebasto closed this May 24, 2021
@hebasto
hebasto deleted the 200816-size branch May 24, 2021 10:32
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants