Skip to content

[Bug] Compiler warnings #2076

@kyeno

Description

@kyeno

PIVX master branch

commit 8d4f649

Machine specs:

  • OS: Gentoo Linux old-hardened profile, grsec+PaX enabled kernel
  • CPU: 32bit x86 Core2Quad Q8200S
  • RAM: 8GB DDR2 800MHz
  • Thread model: posix
  • gcc version 9.3.0 (Gentoo Hardened 9.3.0-r2 p4), default linker
  • Compiling with --without-gui

Compiler throws multiple warnings; mostly -Wdeprecated-copy, but also one potentially dangerous -Wclass-memaccess.

The scary memcpy() problem:

compressor.cpp: In member function 'bool CScriptCompressor::IsToKeyID(CKeyID&) const':
compressor.cpp:16:37: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class CKeyID' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   16 |         memcpy(&hash, &script[3], 20);
      |                                     ^

compressor.cpp: In member function 'bool CScriptCompressor::IsToScriptID(CScriptID&) const':
compressor.cpp:25:37: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class CScriptID' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   25 |         memcpy(&hash, &script[2], 20);
      |                                     ^

The ones causing most of the warnings and being repeated a lot during the compilation (in various references):

masternode.h: In lambda function:
masternode.h:143:83: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  143 |     void SetLastPing(const CMasternodePing& _lastPing) { WITH_LOCK(cs, lastPing = _lastPing;); }
      |                                                                                   ^~~~~~~~~
masternode.cpp: In constructor 'CMasternodeBroadcast::CMasternodeBroadcast(CService, CTxIn, CPubKey, CPubKey, int, const CMasternodePing&)':
masternode.cpp:217:16: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  217 |     lastPing = _lastPing;
      |                ^~~~~~~~~
wallet/wallet.h: In constructor 'CMerkleTx::CMerkleTx(const CTransaction&)':
wallet/wallet.h:871:60: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  871 |     CMerkleTx(const CTransaction& txIn) : CTransaction(txIn)
      |                                                            ^
./sync.h:207:45: note: in definition of macro 'WITH_LOCK'
  207 | #define WITH_LOCK(cs, code) [&] { LOCK(cs); code; }()
      |                                             ^~~~
./primitives/transaction.h:269:19: note: because 'CTransaction' has user-provided 'CTransaction& CTransaction::operator=(const CTransaction&)'
  269 |     CTransaction& operator=(const CTransaction& tx);
      |                   ^~~~~~~~

All the others referred either a bit less often, or occuring just once:

init.cpp: In function 'bool AppInit2()':
init.cpp:1099:41: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
 1099 |             ::minRelayTxFee = CFeeRate(n);
      |                                         ^
miner.cpp: In function 'CBlockTemplate* CreateNewBlock(const CScript&, CWallet*, bool, std::vector<CStakeableOutput>*)':
miner.cpp:295:36: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  295 |                 porphan->feeRate = feeRate;
      |                                    ^~~~~~~
txmempool.cpp: In copy constructor 'CTxMemPoolEntry::CTxMemPoolEntry(const CTxMemPoolEntry&)':
txmempool.cpp:45:13: warning: implicitly-declared 'CTxMemPoolEntry& CTxMemPoolEntry::operator=(const CTxMemPoolEntry&)' is deprecated [-Wdeprecated-copy]
   45 |     *this = other;
      |             ^~~~~
policy/feerate.h:27:5: note: because 'CFeeRate' has user-provided 'CFeeRate::CFeeRate(const CFeeRate&)'
   27 |     CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
      |     ^~~~~~~~
masternode.cpp: In member function 'bool CMasternodePing::CheckAndUpdate(int&, bool, bool)':
masternode.cpp:654:71: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  654 |                 mnodeman.mapSeenMasternodeBroadcast[hash].lastPing = *this;
      |                                                                       ^~~~
./coincontrol.h: In member function 'void CCoinControl::SetNull()':
./coincontrol.h:58:30: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
   58 |         nFeeRate = CFeeRate(0);
      |                              ^
In function 'char* strncpy(char*, const char*, size_t)',
    inlined from 'CMessageHeader::CMessageHeader(const unsigned char (&)[4], const char*, unsigned int)' at protocol.cpp:130:12:
/usr/include/bits/string_fortified.h:106:34: warning: 'char* __builtin_strncpy(char*, const char*, unsigned int)' specified bound 12 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
script/sign.cpp: In member function 'virtual bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>&, const CKeyID&, const CScript&, SigVersion) const':
script/sign.cpp:30:31: warning: catching polymorphic type 'class std::logic_error' by value [-Wcatch-value=]
   30 |     } catch (std::logic_error ex) {
      |                               ^~
spork.h: In member function 'CSporkMessage& CSporkMessage::operator=(const CSporkMessage&)':
spork.h:33:7: warning: implicitly-declared 'CSignedMessage& CSignedMessage::operator=(const CSignedMessage&)' is deprecated [-Wdeprecated-copy]
   33 | class CSporkMessage : public CSignedMessage
      |       ^~~~~~~~~~~~~
./wallet/wallet.h: In constructor 'CMerkleTx::CMerkleTx(const CTransaction&)':
./wallet/wallet.h:871:60: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  871 |     CMerkleTx(const CTransaction& txIn) : CTransaction(txIn)
      |                                                            ^
In file included from sapling/sapling_operation.cpp:5:
./sapling/sapling_operation.h: In member function 'CTransaction SaplingOperation::getFinalTx()':
./sapling/sapling_operation.h:107:40: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  107 |     CTransaction getFinalTx() { return finalTx; }
      |                                        ^~~~~~~
policy/fees.cpp: In constructor 'CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate&)':
policy/fees.cpp:301:84: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  301 |     minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee;
      |                                                                                    ^~~~~~~~~~~~
./budget/budgetvote.h: In member function 'CBudgetVote& CBudgetVote::operator=(const CBudgetVote&)':
./budget/budgetvote.h:17:7: warning: implicitly-declared 'CSignedMessage& CSignedMessage::operator=(const CSignedMessage&)' is deprecated [-Wdeprecated-copy]
   17 | class CBudgetVote : public CSignedMessage
      |       ^~~~~~~~~~~
./budget/finalizedbudgetvote.h: In member function 'CFinalizedBudgetVote& CFinalizedBudgetVote::operator=(const CFinalizedBudgetVote&)':
./budget/finalizedbudgetvote.h:18:7: warning: implicitly-declared 'CSignedMessage& CSignedMessage::operator=(const CSignedMessage&)' is deprecated [-Wdeprecated-copy]
   18 | class CFinalizedBudgetVote : public CSignedMessage
      |       ^~~~~~~~~~~~~~~~~~~~

Those seem to be all I managed to catch and filter out/unify during the quickly scrolling compilation terminal. ;)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions