Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Avoid dereference-of-casted-pointer #10760
+26
−18
Conversation
fanquake
added the
Refactoring
label
Jul 7, 2017
| @@ -10,7 +10,7 @@ | ||
| #include "memusage.h" | ||
| static inline size_t RecursiveDynamicUsage(const CScript& script) { | ||
| - return memusage::DynamicUsage(*static_cast<const CScriptBase*>(&script)); | ||
| + return memusage::DynamicUsage(static_cast<const CScriptBase&>(script)); |
promag
Jul 7, 2017
Contributor
Remove static cast?
return memusage::DynamicUsage(script);In my system it builds fine.
| @@ -94,23 +94,23 @@ bool CWalletDB::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey) | ||
| bool CWalletDB::WriteCScript(const uint160& hash, const CScript& redeemScript) | ||
| { | ||
| - return WriteIC(std::make_pair(std::string("cscript"), hash), *(const CScriptBase*)(&redeemScript), false); | ||
| + return WriteIC(std::make_pair(std::string("cscript"), hash), static_cast<const CScriptBase&>(redeemScript), false); |
promag
Jul 7, 2017
•
Contributor
Removing the cast, shouldn't the compiler resolve to:
template<typename Stream, unsigned int N, typename T>
inline void Serialize(Stream& os, const prevector<N, T>& v)If not I think we could implement CScript::Serialize to call super and drop all of these casts.
|
tACK. |
|
utACK 0aadc11 |
What is the rationale here? Just code cleanup? |
|
Yes, cleanup. The existing practice risks hiding some bugs. |
|
utACK 0aadc11 |
sipa
merged commit 0aadc11
into
bitcoin:master
Jul 15, 2017
1 check passed
continuous-integration/travis-ci/pr
The Travis CI build passed
Details
sipa
added a commit
that referenced
this pull request
Jul 15, 2017
|
|
sipa |
10b22e3
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sipa commentedJul 7, 2017
And prefer a static_cast to the intended reference type.