diff --git a/core/shared/platform/windows/platform_internal.h b/core/shared/platform/windows/platform_internal.h index 77bf8497..a537161f 100644 --- a/core/shared/platform/windows/platform_internal.h +++ b/core/shared/platform/windows/platform_internal.h @@ -183,9 +183,6 @@ typedef uint32_t os_raw_file_handle; // implementation of vprintf on debug builds so output from WASI libc is sent to // the debugger and not lost completely. #if !defined(BH_VPRINTF) && !defined(NDEBUG) && WINAPI_PARTITION_DESKTOP == 0 -int -uwp_print_to_debugger(const char *format, va_list ap); - #define BH_VPRINTF uwp_print_to_debugger #define UWP_DEFAULT_VPRINTF #endif diff --git a/core/shared/platform/windows/win_util.c b/core/shared/platform/windows/win_util.c index 212db6b8..50c446d6 100644 --- a/core/shared/platform/windows/win_util.c +++ b/core/shared/platform/windows/win_util.c @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include "platform_common.h" #include "win_util.h" __wasi_timestamp_t @@ -69,17 +70,19 @@ uwp_print_to_debugger(const char *format, va_list ap) char *buf = stack_buf; int ret = vsnprintf(stack_buf, sizeof(stack_buf), format, ap); - if (ret >= sizeof(stack_buf)) { + if ((size_t)ret >= sizeof(stack_buf)) { // Allocate an extra byte for the null terminator. - char *heap_buf = BH_MALLOC(ret + 1); + char *heap_buf = BH_MALLOC((unsigned int)(ret) + 1); buf = heap_buf; if (heap_buf == NULL) { - errno = ENOMEM; - return -1; + // Output as much as we can to the debugger if allocating a buffer + // fails. + OutputDebugStringA(stack_buf); + return ret; } - ret = vsnprintf(heap_buf, ret + 1, format, ap); + ret = vsnprintf(heap_buf, (size_t)ret + 1, format, ap); } if (ret >= 0)