Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unsuccessful fseek(...):s #13149

Merged
merged 2 commits into from May 7, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+10 −3
Diff settings

Always

Just for now

Copy path View file
@@ -268,7 +268,9 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
CBlockHeader header;
try {
file >> header;
fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
return error("%s: fseek(...) failed", __func__);

This comment has been minimized.

Copy link
@laanwj

laanwj May 2, 2018

Member

LGTM

}
file >> tx;
} catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
Copy path View file
@@ -254,7 +254,10 @@ void BCLog::Logger::ShrinkDebugFile()
{
// Restart the file with some of the end
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
fseek(file, -((long)vch.size()), SEEK_END);
if (fseek(file, -((long)vch.size()), SEEK_END)) {

This comment has been minimized.

Copy link
@laanwj

laanwj May 2, 2018

Member

Not sure what should be done here. As-is it will silently fail to shrink the log file but should continue logging otherwise? Maybe log an error message?

This comment has been minimized.

Copy link
@jonasschnelli

jonasschnelli May 3, 2018

Member

Agree with @laanwj: an additional error message would make sense.

fclose(file);
return;
}
int nBytes = fread(vch.data(), 1, vch.size(), file);
fclose(file);

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

This comment has been minimized.

Copy link
@laanwj

laanwj May 2, 2018

Member

Just returning here is fine - this call is only advisory.

}
while (length > 0) {
unsigned int now = 65536;
if (length < now)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.