Skip to content

Commit

Permalink
Fix varargs usage.
Browse files Browse the repository at this point in the history
Regression from leela-zero#1388. Fixes issue leela-zero#1424.

(cherry picked from commit 62ddf58)
  • Loading branch information
gcp authored and ThorAvaTahr committed Aug 13, 2018
1 parent 46b6506 commit 68894e3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,23 @@ void Utils::myprintf(const char *fmt, ...) {
}
}

static void gtp_fprintf(FILE* file, const std::string& prefix,
const char *fmt, va_list ap) {
fprintf(file, "%s ", prefix.c_str());
vfprintf(file, fmt, ap);
fprintf(file, "\n\n");
}

static void gtp_base_printf(int id, std::string prefix,
const char *fmt, va_list ap) {
if (id != -1) {
prefix += std::to_string(id);
}
prefix += " ";

Utils::gtp_printf_raw(prefix.c_str());
Utils::gtp_printf_raw(fmt, ap);
Utils::gtp_printf_raw("\n\n");

gtp_fprintf(stdout, prefix, fmt, ap);
if (cfg_logfile_handle) {
std::lock_guard<std::mutex> lock(IOmutex);
gtp_fprintf(cfg_logfile_handle, prefix, fmt, ap);
}
}

void Utils::gtp_printf(int id, const char *fmt, ...) {
Expand All @@ -118,11 +124,14 @@ void Utils::gtp_printf_raw(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vfprintf(stdout, fmt, ap);
va_end(ap);

if (cfg_logfile_handle) {
std::lock_guard<std::mutex> lock(IOmutex);
va_start(ap, fmt);
vfprintf(cfg_logfile_handle, fmt, ap);
va_end(ap);
}
va_end(ap);
}

void Utils::gtp_fail_printf(int id, const char *fmt, ...) {
Expand Down

0 comments on commit 68894e3

Please sign in to comment.