fix logging on Windows sometimes not being null-terminated

This commit is contained in:
LazyBumHorse 2019-08-15 13:39:19 +02:00
parent 20846796cd
commit f51e50a423
2 changed files with 26 additions and 6 deletions

View File

@ -357,12 +357,14 @@ static void create_gl_context(HWND hwnd, bool *quit)
wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
gfx_ctx_wgl_get_proc_address("wglGetExtensionsStringARB");
if (wglGetExtensionsStringARB)
extensions = wglGetExtensionsStringARB(win32_hdc);
RARCH_LOG("[WGL] extensions: %s\n", extensions);
if (wgl_has_extension("WGL_EXT_swap_control_tear", extensions))
{
RARCH_LOG("[WGL]: Adaptive VSync supported.\n");
wgl_adaptive_vsync = true;
extensions = wglGetExtensionsStringARB(win32_hdc);
RARCH_LOG("[WGL] extensions: %s\n", extensions);
if (wgl_has_extension("WGL_EXT_swap_control_tear", extensions))
{
RARCH_LOG("[WGL]: Adaptive VSync supported.\n");
wgl_adaptive_vsync = true;
}
}
}
}

View File

@ -218,9 +218,27 @@ void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap)
#else
FILE *fp = (FILE*)log_file_fp;
#if defined(HAVE_QT) || defined(__WINRT__)
int ret;
char buffer[256];
buffer[0] = '\0';
vsnprintf(buffer, sizeof(buffer), fmt, ap);
ret = vsnprintf(buffer, sizeof(buffer), fmt, ap);
/* ensure null termination and line break in error case */
if (ret < 0)
{
int end;
buffer[sizeof buffer - 1] = '\0';
end = strlen(buffer) - 1;
if (end >= 0)
{
buffer[end] = '\n';
}
else
{
buffer[0] = '\n';
buffer[1] = '\0';
}
}
if (fp)
{