The two changes make the code more self-documenting and also allow to remove 5 file-wide suppressions for the module
Avoid integer sanitizer warnings in chain.o #24146
pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2201-intChain changing 3 files +2 −8-
MarcoFalke commented at 9:51 AM on January 25, 2022: member
-
Avoid integer sanitizer warnings in chain.o fa832103aa
- MarcoFalke added the label Refactoring on Jan 25, 2022
- PastaPastaPasta approved
-
PastaPastaPasta commented at 8:42 AM on January 27, 2022: contributor
very simple refactoring PR that makes complete sense, glad to see functional style casts, not c-style casts 😉
utACK fa832103aaa61e93b78ece9dd68c245a41afa6b6
- luke-jr approved
-
luke-jr commented at 11:12 PM on January 29, 2022: member
utACK
-
in src/chain.h:465 in fa832103aa
461 | @@ -462,7 +462,7 @@ class CChain 462 | /** Return the maximal height in the chain. Is equal to chain.Tip() ? chain.Tip()->nHeight : -1. */ 463 | int Height() const 464 | { 465 | - return vChain.size() - 1; 466 | + return int(vChain.size()) - 1;
jonatack commented at 10:28 PM on January 30, 2022:What is the advantage of this approach instead of static casts? i.e. if braced initialization is used the compiler suggests the latter.
chain.cpp:154:27: error: non-constant-expression cannot be narrowed from type 'uint64_t' (aka 'unsigned long') to 'int64_t' (aka 'long') in initializer list [-Wc++11-narrowing] return sign * int64_t{r.GetLow64()}; ^~~~~~~~~~~~ chain.cpp:154:27: note: insert an explicit cast to silence this issue return sign * int64_t{r.GetLow64()}; ^~~~~~~~~~~~ static_cast<int64_t>( ) 1 error generated. .../... ./chain.h:478:20: error: non-constant-expression cannot be narrowed from type 'std::vector::size_type' (aka 'unsigned long') to 'int' in initializer list [-Wc++11-narrowing] return int{vChain.size()} - 1; ^~~~~~~~~~~~~ ./chain.h:478:20: note: insert an explicit cast to silence this issue return int{vChain.size()} - 1; ^~~~~~~~~~~~~ static_cast<int>( ) 1 error generated.
MarcoFalke commented at 7:32 AM on January 31, 2022:The two give the same result, but one of them is less typing and bloat.
jonatack commented at 10:31 PM on January 30, 2022: memberGreat to see all the suppressions this can allow removing.
ACK fa832103aaa61e93b78ece9dd68c245a41afa6b6
MarcoFalke merged this on Jan 31, 2022MarcoFalke closed this on Jan 31, 2022MarcoFalke deleted the branch on Jan 31, 2022sidhujag referenced this in commit c7ee1ae6eb on Feb 1, 2022Fabcien referenced this in commit ba835da240 on Dec 9, 2022DrahtBot locked this on Jan 31, 2023ContributorsLabels
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-17 06:14 UTC
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-17 06:14 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me