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

Refactor File::Print function #1100

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/game/common/system/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,26 @@ void File::Close()

bool File::Print(const char *format, ...)
{
va_list va;
char buffer[10240];

va_start(va, format);

if ((m_access & TEXT) == 0) {
va_end(va);
return false;
}

// Format our message to be written out
int length = vsnprintf(buffer, sizeof(buffer), format, va);
// Thyme specific: Function body was refactored.
bool success = false;

if ((m_access & TEXT) != 0) {
va_list va;
va_start(va, format);
// Format the message to be written out.
char buffer[10240];
const int length = vsnprintf(buffer, sizeof(buffer), format, va);

if (length < sizeof(buffer)) {
// Only write if the message was not truncated.
const int written = Write(buffer, length);
success = written == length;
}

// Only write if we didn't truncate due to buffer overrun.
if (length >= sizeof(buffer)) {
va_end(va);
return false;
}

va_end(va);
return length == Write(buffer, length);
return success;
}

int File::Size()
Expand Down
Loading