Skip to content

Commit

Permalink
Merge pull request #69 from sjneph/compile-warnings-round1
Browse files Browse the repository at this point in the history
Removed global namespace declarations; fixed compiler warnings
  • Loading branch information
cygnusxi authored Jan 30, 2022
2 parents d30f107 + 42ba35b commit d721c6f
Show file tree
Hide file tree
Showing 83 changed files with 1,619 additions and 1,538 deletions.
9 changes: 6 additions & 3 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include "addrman.h"

using namespace std;
#include <algorithm>
#include <map>
#include <set>
#include <vector>

int CAddrInfo::GetTriedBucket(const std::vector<unsigned char> &nKey) const
{
Expand Down Expand Up @@ -324,7 +327,7 @@ bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePen
bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
int64 nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
if (addr.nTime && (!pinfo->nTime || pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty))
pinfo->nTime = max((int64)0, addr.nTime - nTimePenalty);
pinfo->nTime = std::max((int64)0, addr.nTime - nTimePenalty);

// add services
pinfo->nServices |= addr.nServices;
Expand All @@ -349,7 +352,7 @@ bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePen
return false;
} else {
pinfo = Create(addr, source, &nId);
pinfo->nTime = max((int64)0, (int64)pinfo->nTime - nTimePenalty);
pinfo->nTime = std::max((int64)0, (int64)pinfo->nTime - nTimePenalty);
// printf("Added %s [nTime=%fhr]\n", pinfo->ToString().c_str(), (GetAdjustedTime() - pinfo->nTime) / 3600.0);
nNew++;
fNew = true;
Expand Down
15 changes: 8 additions & 7 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#include "sync.h"
#include "ui_interface.h"

using namespace std;
#include <map>
#include <utility>

map<uint256, CAlert> mapAlerts;
std::map<uint256, CAlert> mapAlerts;
CCriticalSection cs_mapAlerts;

static const char* pszMainKey = "043fa441fd4203d03f5df2b75ea14e36f20d39f43e7a61aa7552ab9bcd7ecb0e77a3be4585b13fcdaa22ef6e51f1ff6f2929bec2494385b086fb86610e33193195";
Expand Down Expand Up @@ -51,8 +52,8 @@ std::string CUnsignedAlert::ToString() const
return strprintf(
"CAlert(\n"
" nVersion = %d\n"
" nRelayUntil = %"PRI64d"\n"
" nExpiration = %"PRI64d"\n"
" nRelayUntil = %" PRI64d "\n"
" nExpiration = %" PRI64d "\n"
" nID = %d\n"
" nCancel = %d\n"
" setCancel = %s\n"
Expand Down Expand Up @@ -161,7 +162,7 @@ CAlert CAlert::getAlertByHash(const uint256 &hash)
CAlert retval;
{
LOCK(cs_mapAlerts);
map<uint256, CAlert>::iterator mi = mapAlerts.find(hash);
std::map<uint256, CAlert>::iterator mi = mapAlerts.find(hash);
if(mi != mapAlerts.end())
retval = mi->second;
}
Expand Down Expand Up @@ -200,7 +201,7 @@ bool CAlert::ProcessAlert()
{
LOCK(cs_mapAlerts);
// Cancel previous alerts
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
for (std::map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
{
const CAlert& alert = (*mi).second;
if (Cancels(alert))
Expand Down Expand Up @@ -231,7 +232,7 @@ bool CAlert::ProcessAlert()
}

// Add to mapAlerts
mapAlerts.insert(make_pair(GetHash(), *this));
mapAlerts.insert(std::make_pair(GetHash(), *this));
// Notify UI if it applies to me
if(AppliesToMe())
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
Expand Down
6 changes: 3 additions & 3 deletions src/allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef curecoin_ALLOCATORS_H
#define curecoin_ALLOCATORS_H

#include <string.h>
#include <cstring>
#include <string>
#include <boost/thread/mutex.hpp>
#include <map>
Expand Down Expand Up @@ -212,7 +212,7 @@ struct secure_allocator : public std::allocator<T>
{
if (p != NULL)
{
memset(p, 0, sizeof(T) * n);
std::memset(p, 0, sizeof(T) * n);
LockedPageManager::instance.UnlockRange(p, sizeof(T) * n);
}
std::allocator<T>::deallocate(p, n);
Expand Down Expand Up @@ -246,7 +246,7 @@ struct zero_after_free_allocator : public std::allocator<T>
void deallocate(T* p, std::size_t n)
{
if (p != NULL)
memset(p, 0, sizeof(T) * n);
std::memset(p, 0, sizeof(T) * n);
std::allocator<T>::deallocate(p, n);
}
};
Expand Down
19 changes: 10 additions & 9 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef curecoin_BASE58_H
#define curecoin_BASE58_H

#include <cstring>
#include <string>
#include <vector>
#include "bignum.h"
Expand Down Expand Up @@ -150,7 +151,7 @@ inline bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRe
return false;
}
uint256 hash = Hash(vchRet.begin(), vchRet.end()-4);
if (memcmp(&hash, &vchRet.end()[-4], 4) != 0)
if (std::memcmp(&hash, &vchRet.end()[-4], 4) != 0)
{
vchRet.clear();
return false;
Expand Down Expand Up @@ -190,15 +191,15 @@ class CBase58Data
{
// zero the memory, as it may contain sensitive data
if (!vchData.empty())
memset(&vchData[0], 0, vchData.size());
std::memset(&vchData[0], 0, vchData.size());
}

void SetData(int nVersionIn, const void* pdata, size_t nSize)
{
nVersion = nVersionIn;
vchData.resize(nSize);
if (!vchData.empty())
memcpy(&vchData[0], pdata, nSize);
std::memcpy(&vchData[0], pdata, nSize);
}

void SetData(int nVersionIn, const unsigned char *pbegin, const unsigned char *pend)
Expand All @@ -220,8 +221,8 @@ class CBase58Data
nVersion = vchTemp[0];
vchData.resize(vchTemp.size() - 1);
if (!vchData.empty())
memcpy(&vchData[0], &vchTemp[1], vchData.size());
memset(&vchTemp[0], 0, vchTemp.size());
std::memcpy(&vchData[0], &vchTemp[1], vchData.size());
std::memset(&vchTemp[0], 0, vchTemp.size());
return true;
}

Expand Down Expand Up @@ -353,13 +354,13 @@ class CcurecoinAddress : public CBase58Data
case PUBKEY_ADDRESS:
case PUBKEY_ADDRESS_TEST: {
uint160 id;
memcpy(&id, &vchData[0], 20);
std::memcpy(&id, &vchData[0], 20);
return CKeyID(id);
}
case SCRIPT_ADDRESS:
case SCRIPT_ADDRESS_TEST: {
uint160 id;
memcpy(&id, &vchData[0], 20);
std::memcpy(&id, &vchData[0], 20);
return CScriptID(id);
}
}
Expand All @@ -373,7 +374,7 @@ class CcurecoinAddress : public CBase58Data
case PUBKEY_ADDRESS:
case PUBKEY_ADDRESS_TEST: {
uint160 id;
memcpy(&id, &vchData[0], 20);
std::memcpy(&id, &vchData[0], 20);
keyID = CKeyID(id);
return true;
}
Expand Down Expand Up @@ -414,7 +415,7 @@ class CcurecoinSecret : public CBase58Data
{
CSecret vchSecret;
vchSecret.resize(32);
memcpy(&vchSecret[0], &vchData[0], 32);
std::memcpy(&vchSecret[0], &vchData[0], 32);
fCompressedOut = vchData.size() == 33;
return vchSecret;
}
Expand Down
13 changes: 7 additions & 6 deletions src/crypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <openssl/aes.h>
#include <openssl/evp.h>
#include <vector>
#include <cstring>
#include <string>
#ifdef WIN32
#include <windows.h>
Expand All @@ -24,8 +25,8 @@ bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::v

if (i != (int)WALLET_CRYPTO_KEY_SIZE)
{
memset(&chKey, 0, sizeof chKey);
memset(&chIV, 0, sizeof chIV);
std::memset(&chKey, 0, sizeof chKey);
std::memset(&chIV, 0, sizeof chIV);
return false;
}

Expand All @@ -38,8 +39,8 @@ bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const std::vector<unsigne
if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_KEY_SIZE)
return false;

memcpy(&chKey[0], &chNewKey[0], sizeof chKey);
memcpy(&chIV[0], &chNewIV[0], sizeof chIV);
std::memcpy(&chKey[0], &chNewKey[0], sizeof chKey);
std::memcpy(&chIV[0], &chNewIV[0], sizeof chIV);

fKeySet = true;
return true;
Expand Down Expand Up @@ -104,7 +105,7 @@ bool EncryptSecret(CKeyingMaterial& vMasterKey, const CSecret &vchPlaintext, con
{
CCrypter cKeyCrypter;
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE);
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE);
std::memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE);
if(!cKeyCrypter.SetKey(vMasterKey, chIV))
return false;
return cKeyCrypter.Encrypt((CKeyingMaterial)vchPlaintext, vchCiphertext);
Expand All @@ -114,7 +115,7 @@ bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned
{
CCrypter cKeyCrypter;
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE);
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE);
std::memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE);
if(!cKeyCrypter.SetKey(vMasterKey, chIV))
return false;
return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext));
Expand Down
6 changes: 4 additions & 2 deletions src/crypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "key.h"
#include "serialize.h"

#include <cstring>

const unsigned int WALLET_CRYPTO_KEY_SIZE = 32;
const unsigned int WALLET_CRYPTO_SALT_SIZE = 8;

Expand Down Expand Up @@ -76,8 +78,8 @@ class CCrypter

void CleanKey()
{
memset(&chKey, 0, sizeof chKey);
memset(&chIV, 0, sizeof chIV);
std::memset(&chKey, 0, sizeof chKey);
std::memset(&chIV, 0, sizeof chIV);
fKeySet = false;
}

Expand Down
Loading

0 comments on commit d721c6f

Please sign in to comment.