Skip to content

Commit

Permalink
Merge pull request #32045 from neikeq/fix-cannot-create-mono-log-file
Browse files Browse the repository at this point in the history
Mono: Fix unable to create log file due to str_format bug
  • Loading branch information
akien-mga authored Sep 8, 2019
2 parents e9f49a6 + 3dcd7e5 commit 24e1039
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/mono/mono_gd/gd_mono_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void GDMonoLog::initialize() {

log_file = FileAccess::open(log_file_path, FileAccess::WRITE);
if (!log_file) {
ERR_PRINT("Mono: Cannot create log file.");
ERR_PRINTS("Mono: Cannot create log file at: " + log_file_path);
}
}

Expand Down
10 changes: 7 additions & 3 deletions modules/mono/utils/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,26 @@ String str_format(const char *p_format, ...) {
#endif

#if defined(MINGW_ENABLED) || defined(_MSC_VER) && _MSC_VER < 1900
#define vsnprintf(m_buffer, m_count, m_format, m_argptr) vsnprintf_s(m_buffer, m_count, _TRUNCATE, m_format, m_argptr)
#define gd_vsnprintf(m_buffer, m_count, m_format, m_args_copy) vsnprintf_s(m_buffer, m_count, _TRUNCATE, m_format, m_args_copy)
#define gd_vscprintf(m_format, m_args_copy) _vscprintf(m_format, m_args_copy)
#else
#define gd_vsnprintf(m_buffer, m_count, m_format, m_args_copy) vsnprintf(m_buffer, m_count, m_format, m_args_copy)
#define gd_vscprintf(m_format, m_args_copy) vsnprintf(NULL, 0, p_format, m_args_copy)
#endif

String str_format(const char *p_format, va_list p_list) {
va_list list;

va_copy(list, p_list);
int len = vsnprintf(NULL, 0, p_format, list);
int len = gd_vscprintf(p_format, list);
va_end(list);

len += 1; // for the trailing '/0'

char *buffer(memnew_arr(char, len));

va_copy(list, p_list);
vsnprintf(buffer, len, p_format, list);
gd_vsnprintf(buffer, len, p_format, list);
va_end(list);

String res(buffer);
Expand Down

0 comments on commit 24e1039

Please sign in to comment.