Handle unsuccessful fseek(...):s

This commit is contained in:
practicalswift 2018-05-02 12:12:55 +02:00
parent 57c57df86f
commit 29c9bdcc14
3 changed files with 10 additions and 3 deletions

View file

@ -268,7 +268,9 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
CBlockHeader header; CBlockHeader header;
try { try {
file >> header; file >> header;
fseek(file.Get(), postx.nTxOffset, SEEK_CUR); if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
return error("%s: fseek(...) failed", __func__);
}
file >> tx; file >> tx;
} catch (const std::exception& e) { } catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what()); return error("%s: Deserialize or I/O error - %s", __func__, e.what());

View file

@ -254,7 +254,10 @@ void BCLog::Logger::ShrinkDebugFile()
{ {
// Restart the file with some of the end // Restart the file with some of the end
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0); std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
fseek(file, -((long)vch.size()), SEEK_END); if (fseek(file, -((long)vch.size()), SEEK_END)) {
fclose(file);
return;
}
int nBytes = fread(vch.data(), 1, vch.size(), file); int nBytes = fread(vch.data(), 1, vch.size(), file);
fclose(file); fclose(file);

View file

@ -887,7 +887,9 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
// Fallback version // Fallback version
// TODO: just write one byte per block // TODO: just write one byte per block
static const char buf[65536] = {}; static const char buf[65536] = {};
fseek(file, offset, SEEK_SET); if (fseek(file, offset, SEEK_SET)) {
return;
}
while (length > 0) { while (length > 0) {
unsigned int now = 65536; unsigned int now = 65536;
if (length < now) if (length < now)