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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,7 +254,11 @@ 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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with @laanwj: an additional error message would make sense. |
||
LogPrintf("Failed to shrink debug log file: fseek(...) failed\n"); | ||
fclose(file); | ||
return; | ||
} | ||
int nBytes = fread(vch.data(), 1, vch.size(), file); | ||
fclose(file); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just returning here is fine - this call is only advisory. |
||
} | ||
while (length > 0) { | ||
unsigned int now = 65536; | ||
if (length < now) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM