From 5c38c6455fc6ac330b94d1a6fe7833de9e3c56ff Mon Sep 17 00:00:00 2001 From: jpark37 Date: Thu, 27 Feb 2020 05:28:05 -0800 Subject: [PATCH] win-capture: Refactor create_hook_info --- plugins/win-capture/graphics-hook-info.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/win-capture/graphics-hook-info.h b/plugins/win-capture/graphics-hook-info.h index 3defb00a1..04546e489 100644 --- a/plugins/win-capture/graphics-hook-info.h +++ b/plugins/win-capture/graphics-hook-info.h @@ -109,9 +109,16 @@ struct hook_info { static inline HANDLE create_hook_info(DWORD id) { - wchar_t new_name[64]; - _snwprintf(new_name, 64, L"%s%lu", SHMEM_HOOK_INFO, id); + HANDLE handle = NULL; - return CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, - sizeof(struct hook_info), new_name); + wchar_t new_name[64]; + const int len = swprintf(new_name, _countof(new_name), + SHMEM_HOOK_INFO L"%lu", id); + if (len > 0) { + handle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, + PAGE_READWRITE, 0, + sizeof(struct hook_info), new_name); + } + + return handle; }