Skip to content

Commit bd83704

Browse files
committed
Merge #13149: Handle unsuccessful fseek(...):s
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift) 29c9bdc Handle unsuccessful fseek(...):s (practicalswift) Pull request description: Handle unsuccessful `fseek(...)`:s. **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s? Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876
2 parents 6a01a50 + 20ce5af commit bd83704

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/index/txindex.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
268268
CBlockHeader header;
269269
try {
270270
file >> header;
271-
fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
271+
if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
272+
return error("%s: fseek(...) failed", __func__);
273+
}
272274
file >> tx;
273275
} catch (const std::exception& e) {
274276
return error("%s: Deserialize or I/O error - %s", __func__, e.what());

src/logging.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ void BCLog::Logger::ShrinkDebugFile()
253253
{
254254
// Restart the file with some of the end
255255
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
256-
fseek(file, -((long)vch.size()), SEEK_END);
256+
if (fseek(file, -((long)vch.size()), SEEK_END)) {
257+
LogPrintf("Failed to shrink debug log file: fseek(...) failed\n");
258+
fclose(file);
259+
return;
260+
}
257261
int nBytes = fread(vch.data(), 1, vch.size(), file);
258262
fclose(file);
259263

src/util.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,9 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
887887
// Fallback version
888888
// TODO: just write one byte per block
889889
static const char buf[65536] = {};
890-
fseek(file, offset, SEEK_SET);
890+
if (fseek(file, offset, SEEK_SET)) {
891+
return;
892+
}
891893
while (length > 0) {
892894
unsigned int now = 65536;
893895
if (length < now)

0 commit comments

Comments
 (0)