New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve readability of DecodeBase58Check(...) #10961
Improve readability of DecodeBase58Check(...) #10961
Conversation
95cb550
to
6ab2ce8
Compare
utACK 6ab2ce8. |
This seems to be an over-cosmetic change... not sure if its worth. |
src/base58.cpp
Outdated
@@ -136,7 +136,7 @@ bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet) | |||
} | |||
// re-calculate the checksum, ensure it matches the included 4-byte checksum | |||
uint256 hash = Hash(vchRet.begin(), vchRet.end() - 4); | |||
if (memcmp(&hash, &vchRet.end()[-4], 4) != 0) { | |||
if (memcmp(&hash, vchRet.data() + vchRet.size() - 4, 4) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there's some reason vchRet.end() - 4
doesn't work (pointer versus iterator conflict or something like that)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah vchRet.end()-4
would still be an iterator I believe, so you'd have to do some ugly thing like &*(vchRet.end()-4)
to make it into a pointer iirc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about &vchRet[vchRet.size() - 4]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Believe that would work, and yeah that's a lot clearer imo 👍
6ab2ce8
to
affe927
Compare
3fe79d2
to
c6a995e
Compare
@laanwj @meshcollider @sipa Thanks for reviewing! Changed to |
Just confirmed this should be identical behavior, ACK c6a995e |
Travis have completed without errors, but GitHub still reports "1 pending check". |
Seems like Travis CI is stuck. Anyone able to re-start Travis? :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK c6a995e
utACK c6a995e |
c6a995e Improve readability of DecodeBase58Check(...) (practicalswift) Pull request description: Use the more readable form ... ```c++ &vchRet[vchRet.size() - 4] ``` ... instead of ... ```c++ &v.end()[-n] ``` Has the added benefit of eliminating a spurious static analyzer warning about improper use of negative values. Tree-SHA512: 5895310c189e9322082c28f34342ff9a6c238e2cae3f204521111c8a7981bc555af60b42de082c91608c1125dfc244a65c4faf929249a067a51435e2be74cb39
c6a995e Improve readability of DecodeBase58Check(...) (practicalswift) Pull request description: Use the more readable form ... ```c++ &vchRet[vchRet.size() - 4] ``` ... instead of ... ```c++ &v.end()[-n] ``` Has the added benefit of eliminating a spurious static analyzer warning about improper use of negative values. Tree-SHA512: 5895310c189e9322082c28f34342ff9a6c238e2cae3f204521111c8a7981bc555af60b42de082c91608c1125dfc244a65c4faf929249a067a51435e2be74cb39
c6a995e Improve readability of DecodeBase58Check(...) (practicalswift) Pull request description: Use the more readable form ... ```c++ &vchRet[vchRet.size() - 4] ``` ... instead of ... ```c++ &v.end()[-n] ``` Has the added benefit of eliminating a spurious static analyzer warning about improper use of negative values. Tree-SHA512: 5895310c189e9322082c28f34342ff9a6c238e2cae3f204521111c8a7981bc555af60b42de082c91608c1125dfc244a65c4faf929249a067a51435e2be74cb39
c6a995e Improve readability of DecodeBase58Check(...) (practicalswift) Pull request description: Use the more readable form ... ```c++ &vchRet[vchRet.size() - 4] ``` ... instead of ... ```c++ &v.end()[-n] ``` Has the added benefit of eliminating a spurious static analyzer warning about improper use of negative values. Tree-SHA512: 5895310c189e9322082c28f34342ff9a6c238e2cae3f204521111c8a7981bc555af60b42de082c91608c1125dfc244a65c4faf929249a067a51435e2be74cb39
c6a995e Improve readability of DecodeBase58Check(...) (practicalswift) Pull request description: Use the more readable form ... ```c++ &vchRet[vchRet.size() - 4] ``` ... instead of ... ```c++ &v.end()[-n] ``` Has the added benefit of eliminating a spurious static analyzer warning about improper use of negative values. Tree-SHA512: 5895310c189e9322082c28f34342ff9a6c238e2cae3f204521111c8a7981bc555af60b42de082c91608c1125dfc244a65c4faf929249a067a51435e2be74cb39
aa633c8 CBase58Data::SetString: cleanse the full vector (Kaz Wesley) 0b77f8a Improve readability of DecodeBase58Check(...) (practicalswift) dadadee Use prefix operator in for loop of DecodeBase58. (Jiaxing Wang) 305c382 base58: Improve DecodeBase58 performance. (Jiaxing Wang) 3cb418b Improve EncodeBase58 performance (João Barbosa) 4d17f71 don't try to decode invalid encoded ext keys (Jonas Schnelli) eef4ec6 extend bip32 tests to cover Base58c/CExtKey decode (furszy) 7239aaf fix and extend CBitcoinExtKeyBase template - fix Decode call (req. only one param) - add constructor for base58c->CExtKey (furszy) 13f09c3 remove unused inv from ConnectTip() (furszy) Pull request description: Coming from: * bitcoin#6468 . * bitcoin#7656 . * bitcoin#7922 * bitcoin#8736 . * bitcoin#10961 . ACKs for top commit: random-zebra: ACK aa633c8 Fuzzbawls: ACK aa633c8 Tree-SHA512: 3add3106a847b0b3d768df2c4ab5eae7d009e3820998fb5a4cd274169c64622e83ecd14dca51c31f3f6053199834129a1c6920b7ef1193632339297a041173d6
c6a995e Improve readability of DecodeBase58Check(...) (practicalswift) Pull request description: Use the more readable form ... ```c++ &vchRet[vchRet.size() - 4] ``` ... instead of ... ```c++ &v.end()[-n] ``` Has the added benefit of eliminating a spurious static analyzer warning about improper use of negative values. Tree-SHA512: 5895310c189e9322082c28f34342ff9a6c238e2cae3f204521111c8a7981bc555af60b42de082c91608c1125dfc244a65c4faf929249a067a51435e2be74cb39
c6a995e Improve readability of DecodeBase58Check(...) (practicalswift) Pull request description: Use the more readable form ... ```c++ &vchRet[vchRet.size() - 4] ``` ... instead of ... ```c++ &v.end()[-n] ``` Has the added benefit of eliminating a spurious static analyzer warning about improper use of negative values. Tree-SHA512: 5895310c189e9322082c28f34342ff9a6c238e2cae3f204521111c8a7981bc555af60b42de082c91608c1125dfc244a65c4faf929249a067a51435e2be74cb39
Use the more readable form ...
&vchRet[vchRet.size() - 4]
... instead of ...
Has the added benefit of eliminating a spurious static analyzer warning about improper use of negative values.