Make -checkmempool=1 not fail through int32 overflow #6896

Merged
merged 1 commit into from Oct 30, 2015

Conversation

Projects
None yet
6 participants
@sipa
Member

sipa commented Oct 28, 2015

Fix a bug in #6776 discovered by @gmaxwell: -checkmempool=1 causes the internal 32-bit variable to overflow to zero.

@@ -360,7 +360,7 @@ class CTxMemPool
* check does nothing.
*/
void check(const CCoinsViewCache *pcoins) const;
- void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = dFrequency * 4294967296.0; }
+ void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = dFrequency * 4294967295.0; }

This comment has been minimized.

@dcousens

dcousens Oct 28, 2015

Contributor

Any reason not to cast explicitly?
std::static_cast<int>(dFrequency * 4294967295.0)?

IMHO it might have made this more obvious to reviewers.

@dcousens

dcousens Oct 28, 2015

Contributor

Any reason not to cast explicitly?
std::static_cast<int>(dFrequency * 4294967295.0)?

IMHO it might have made this more obvious to reviewers.

This comment has been minimized.

@jgarzik

jgarzik Oct 29, 2015

Contributor

Agree w/ @dcousens

Additionally, raw big numbers with no explanation comment should be avoided. I know it's 2^32 but it's not immediately obvious to every code reader.

This should be uint_max-1 and getdouble() should be similar.

@jgarzik

jgarzik Oct 29, 2015

Contributor

Agree w/ @dcousens

Additionally, raw big numbers with no explanation comment should be avoided. I know it's 2^32 but it's not immediately obvious to every code reader.

This should be uint_max-1 and getdouble() should be similar.

This comment has been minimized.

@dcousens

This comment has been minimized.

Show comment
Hide comment
@dcousens

dcousens Oct 28, 2015

Contributor

ACK

Contributor

dcousens commented Oct 28, 2015

ACK

@laanwj

This comment has been minimized.

Show comment
Hide comment
@laanwj

laanwj Oct 28, 2015

Member

Oops.
Probably needs a range check, >1 and <0 will still silently overflow.

Member

laanwj commented Oct 28, 2015

Oops.
Probably needs a range check, >1 and <0 will still silently overflow.

@dcousens

This comment has been minimized.

Show comment
Hide comment
@dcousens

dcousens Oct 28, 2015

Contributor

@laanwj I think the issue was that it would overflow to 0.
At least that was my understanding.

In any case, a range check would be sane.
Or just min(max(dFrequency, 0), 1)

Contributor

dcousens commented Oct 28, 2015

@laanwj I think the issue was that it would overflow to 0.
At least that was my understanding.

In any case, a range check would be sane.
Or just min(max(dFrequency, 0), 1)

@laanwj

This comment has been minimized.

Show comment
Hide comment
@laanwj

laanwj Oct 28, 2015

Member

Isn't any overflow an issue?

Member

laanwj commented Oct 28, 2015

Isn't any overflow an issue?

@instagibbs

This comment has been minimized.

Show comment
Hide comment
@instagibbs

instagibbs Oct 28, 2015

Member

Right now it doesn't appear overflow as currently used(post-fix), but probably a good idea to internally check.

Member

instagibbs commented Oct 28, 2015

Right now it doesn't appear overflow as currently used(post-fix), but probably a good idea to internally check.

@laanwj

This comment has been minimized.

Show comment
Hide comment
@laanwj

laanwj Oct 30, 2015

Member

Apparently a range clamp is already done in init.cpp. That's good enough, going to merge this.

Member

laanwj commented Oct 30, 2015

Apparently a range clamp is already done in init.cpp. That's good enough, going to merge this.

@laanwj laanwj merged commit e9e6163 into bitcoin:master Oct 30, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

laanwj added a commit that referenced this pull request Oct 30, 2015

Merge pull request #6896
e9e6163 Make -checkmempool=1 not fail through int32 overflow (Pieter Wuille)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment