Avoid unintentional unsigned integer wraparounds#11535
Avoid unintentional unsigned integer wraparounds#11535practicalswift wants to merge 3 commits intobitcoin:masterfrom
Conversation
c8dfc4f to
39b29a7
Compare
|
@laanwj Good point. Fixed! :-) |
|
Added commits from #11547 ("Avoid unintended unsigned integer wraparounds in FormatScript(...) and SplitHostPort(...)") as requested :-) |
36312c2 to
75cd0bb
Compare
3ccdc11 to
d475051
Compare
|
Added a few more wrap-arounds and squashed. Now at 16 fixed wrap-arounds. |
|
We tend to use C-style casts for primitive types... just for brevity. |
d475051 to
0a01b38
Compare
|
@sipa I'll change! Other than that, do the changes look reasonable? :-) |
0a01b38 to
47c89fe
Compare
|
@sipa Now using C-style casts for primitive types :-) |
47c89fe to
14e297d
Compare
|
Added another wraparound fix (this time in Anyone willing to review? :-) |
14e297d to
6ec8af9
Compare
|
Rebased! :-) |
|
Anyone willing to review - ACK or NACK? :-) |
|
Ping? :-) |
|
Do we not care about integer wrap-arounds? If so let me know and I'll close :-) |
|
ACK test changes, they seem straightforward. The other need a cautious review, since they change behavior. (You can split the test changes into a separate pull request, if you want) |
2736c9e Avoid unintentional unsigned integer wraparounds in tests (practicalswift) Pull request description: Avoid unintentional unsigned integer wraparounds in tests. This is a subset of #11535 as suggested by @MarcoFalke :-) Tree-SHA512: 4f4ee8a08870101a3f7451aefa77ae06aaf44e3c3b2f7555faa2b8a8503f97f34e34dffcf65154278f15767dc9823955f52d1aa7b39930b390e57cdf2b65e0f3
|
To increase the likelihood of this PR getting merged – should I limit it to a subset that is low-risk/non-controversial? Please help me find that subset :-) It would be really nice to get rid of these unintended unsigned integer wraparounds. |
|
bac9b8c to
f2fb2e5
Compare
|
I don't have any authority here, I can only offer advice how I would approach this. What do I mean by "this"? I think the code should transition to using signed integers pervasively, everywhere by default, except the places where it needs unsigned integers (such as bit fiddling and modulo-2 arithmetic, a lot of crypto code falls into this category). I think getting there has to be incremental, and during the transition there will probably be a net increase of signed/unsigned casts. But in the end the whole codebase could be built with @practicalswift I believe you've found the issues you've addressed here with for example, take this part of the patch. Maybe it would make more sense to explore what would happen if |
|
If we decide to return sizes and lengths as int64_t, that should probably be documented in the developer notes (coding style) with rationale for doing so. Otherwise it seems like the code could go back and forth over this constantly. |
|
@arvidn Good point regarding splitting this PR into smaller parts. I'll do that. @arvidn @MarcoFalke Are there any parts of this PR that you can ACK or NACK? I'm trying to identify the appropriate parts to split it in :-) |
c8bc42a to
ac8ff23
Compare
src/validation.cpp
Outdated
There was a problem hiding this comment.
How do this avoid overflow?
There was a problem hiding this comment.
It won't decrement when num is 0. The old code would stop the loop, but still decrement.
…lentTime(...) when to.nChainWork <= from.nChainWork
ac8ff23 to
42aba47
Compare
… in tests 2736c9e Avoid unintentional unsigned integer wraparounds in tests (practicalswift) Pull request description: Avoid unintentional unsigned integer wraparounds in tests. This is a subset of bitcoin#11535 as suggested by @MarcoFalke :-) Tree-SHA512: 4f4ee8a08870101a3f7451aefa77ae06aaf44e3c3b2f7555faa2b8a8503f97f34e34dffcf65154278f15767dc9823955f52d1aa7b39930b390e57cdf2b65e0f3
… in tests 2736c9e Avoid unintentional unsigned integer wraparounds in tests (practicalswift) Pull request description: Avoid unintentional unsigned integer wraparounds in tests. This is a subset of bitcoin#11535 as suggested by @MarcoFalke :-) Tree-SHA512: 4f4ee8a08870101a3f7451aefa77ae06aaf44e3c3b2f7555faa2b8a8503f97f34e34dffcf65154278f15767dc9823955f52d1aa7b39930b390e57cdf2b65e0f3
Avoid unintentional unsigned integer wraparounds.