Skip to content

Conversation

@practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Oct 20, 2017

Avoid unintentional unsigned integer wraparounds.

@fanquake fanquake added the Tests label Oct 20, 2017
@practicalswift practicalswift force-pushed the unsigned-integer-wraparounds branch from c8dfc4f to 39b29a7 Compare October 21, 2017 22:32
@practicalswift
Copy link
Contributor Author

@laanwj Good point. Fixed! :-)

@practicalswift
Copy link
Contributor Author

Added commits from #11547 ("Avoid unintended unsigned integer wraparounds in FormatScript(...) and SplitHostPort(...)") as requested :-)

@practicalswift practicalswift changed the title test: Avoid unintentional unsigned integer wraparounds Avoid unintentional unsigned integer wraparounds Oct 22, 2017
@practicalswift practicalswift force-pushed the unsigned-integer-wraparounds branch from 36312c2 to 75cd0bb Compare October 23, 2017 22:10
@practicalswift practicalswift force-pushed the unsigned-integer-wraparounds branch 2 times, most recently from 3ccdc11 to d475051 Compare October 24, 2017 06:28
@practicalswift
Copy link
Contributor Author

practicalswift commented Oct 24, 2017

Added a few more wrap-arounds and squashed. Now at 16 fixed wrap-arounds.

@sipa
Copy link
Member

sipa commented Oct 24, 2017

We tend to use C-style casts for primitive types... just for brevity.

@practicalswift practicalswift force-pushed the unsigned-integer-wraparounds branch from d475051 to 0a01b38 Compare October 24, 2017 06:35
@practicalswift
Copy link
Contributor Author

@sipa I'll change! Other than that, do the changes look reasonable? :-)

@practicalswift practicalswift force-pushed the unsigned-integer-wraparounds branch from 0a01b38 to 47c89fe Compare October 25, 2017 09:04
@practicalswift
Copy link
Contributor Author

@sipa Now using C-style casts for primitive types :-)

@practicalswift practicalswift force-pushed the unsigned-integer-wraparounds branch from 47c89fe to 14e297d Compare October 25, 2017 19:33
@practicalswift
Copy link
Contributor Author

Added another wraparound fix (this time in AcceptBlock(…)) and squashed.

Anyone willing to review? :-)

@practicalswift practicalswift force-pushed the unsigned-integer-wraparounds branch from 14e297d to 6ec8af9 Compare November 9, 2017 15:51
@practicalswift
Copy link
Contributor Author

Rebased! :-)

@maflcko maflcko added Refactoring and removed Tests labels Nov 9, 2017
@practicalswift
Copy link
Contributor Author

Anyone willing to review - ACK or NACK? :-)

@practicalswift
Copy link
Contributor Author

Ping? :-)

@practicalswift
Copy link
Contributor Author

Do we not care about integer wrap-arounds? If so let me know and I'll close :-)

@maflcko
Copy link
Member

maflcko commented Feb 22, 2018

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)

laanwj added a commit that referenced this pull request Mar 5, 2018
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
@practicalswift
Copy link
Contributor Author

practicalswift commented Sep 28, 2018

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.

@flack
Copy link
Contributor

flack commented Sep 28, 2018

Please help me find that subset :-)

@practicalswift see #11535 (comment)

@practicalswift
Copy link
Contributor Author

@flack That subset has already been fixed – see #12516 :-)

@arvidn
Copy link

arvidn commented Nov 5, 2018

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 -Wsign-conversion -Werror, which would be a great place to be in, and with fewer casts.

@practicalswift I believe you've found the issues you've addressed here with -fsanitize=unsigned, right? I think that's a good tool to find the most egregious misuses of unsigned integers, they should probably be the first ones to go. However, perhaps addressing all of these individual spots in a single commit isn't the right slicing or increment towards the goal of reducing misuses of unsigned integers. Perhaps instead, pick one, and fix that one properly, including all the ripple-effects it may have.

for example, take this part of the patch.

Maybe it would make more sense to explore what would happen if GetTxSize() would return an int64_t (which seems like a cleaner solution than casting its result like this).

@maflcko
Copy link
Member

maflcko commented Nov 5, 2018

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.

@practicalswift
Copy link
Contributor Author

practicalswift commented Nov 5, 2018

@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 :-)

@practicalswift practicalswift force-pushed the unsigned-integer-wraparounds branch 2 times, most recently from c8bc42a to ac8ff23 Compare November 7, 2018 09:01
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do this avoid overflow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't decrement when num is 0. The old code would stop the loop, but still decrement.

@practicalswift practicalswift force-pushed the unsigned-integer-wraparounds branch from ac8ff23 to 42aba47 Compare November 11, 2018 18:33
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 12, 2020
… 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
@practicalswift practicalswift deleted the unsigned-integer-wraparounds branch April 10, 2021 19:36
gades pushed a commit to cosanta/cosanta-core that referenced this pull request May 31, 2022
… 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
@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.