0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

add missing CAutoFile::IsNull() check in main

- also use __func__ in error messages related to block files
- minor comment changes and remove space after function name in log
  messages in touched functions
This commit is contained in:
Philip Kaufmann 2014-12-07 12:57:11 +01:00
parent 4b5b263ac0
commit ccd056a30d

View file

@ -1079,6 +1079,8 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
CDiskTxPos postx; CDiskTxPos postx;
if (pblocktree->ReadTxIndex(hash, postx)) { if (pblocktree->ReadTxIndex(hash, postx)) {
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION); CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
if (file.IsNull())
return error("%s: OpenBlockFile failed", __func__);
CBlockHeader header; CBlockHeader header;
try { try {
file >> header; file >> header;
@ -1135,10 +1137,10 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos) bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
{ {
// Open history file to append // Open block file to append
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION); CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
if (fileout.IsNull()) if (fileout.IsNull())
return error("WriteBlockToDisk : OpenBlockFile failed"); return error("%s: OpenBlockFile failed", __func__);
// Write index header // Write index header
unsigned int nSize = fileout.GetSerializeSize(block); unsigned int nSize = fileout.GetSerializeSize(block);
@ -1147,7 +1149,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
// Write block // Write block
long fileOutPos = ftell(fileout.Get()); long fileOutPos = ftell(fileout.Get());
if (fileOutPos < 0) if (fileOutPos < 0)
return error("WriteBlockToDisk : ftell failed"); return error("%s: ftell failed", __func__);
pos.nPos = (unsigned int)fileOutPos; pos.nPos = (unsigned int)fileOutPos;
fileout << block; fileout << block;
@ -1158,10 +1160,10 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
{ {
block.SetNull(); block.SetNull();
// Open history file to read // Open block file to read
CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION); CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
if (filein.IsNull()) if (filein.IsNull())
return error("ReadBlockFromDisk : OpenBlockFile failed"); return error("%s: OpenBlockFile failed", __func__);
// Read block // Read block
try { try {
@ -1173,7 +1175,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
// Check the header // Check the header
if (!CheckProofOfWork(block.GetHash(), block.nBits)) if (!CheckProofOfWork(block.GetHash(), block.nBits))
return error("ReadBlockFromDisk : Errors in block header"); return error("%s: Errors in block header", __func__);
return true; return true;
} }
@ -4540,10 +4542,10 @@ bool CBlockUndo::WriteToDisk(CDiskBlockPos &pos, const uint256 &hashBlock)
bool CBlockUndo::ReadFromDisk(const CDiskBlockPos &pos, const uint256 &hashBlock) bool CBlockUndo::ReadFromDisk(const CDiskBlockPos &pos, const uint256 &hashBlock)
{ {
// Open history file to read // Open undo file to read
CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION); CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
if (filein.IsNull()) if (filein.IsNull())
return error("CBlockUndo::ReadFromDisk : OpenBlockFile failed"); return error("%s: OpenBlockFile failed", __func__);
// Read block // Read block
uint256 hashChecksum; uint256 hashChecksum;
@ -4560,7 +4562,7 @@ bool CBlockUndo::ReadFromDisk(const CDiskBlockPos &pos, const uint256 &hashBlock
hasher << hashBlock; hasher << hashBlock;
hasher << *this; hasher << *this;
if (hashChecksum != hasher.GetHash()) if (hashChecksum != hasher.GetHash())
return error("CBlockUndo::ReadFromDisk : Checksum mismatch"); return error("%s: Checksum mismatch", __func__);
return true; return true;
} }