From f7534e2524d4b14a457540a987e168bc28f61e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 27 Jul 2022 16:34:09 +0200 Subject: Fix memory bug. swprintf_s excepts the NUMBER of characters, not the SIZE of the buffer. The argument is named sizeOfBuffer in the documentation, but don't let that fool you (like it did me). Interestingly enough, this bug causes a crash ONLY when compiling WITHOUT optimizations (at least on my system). The crash was introduced in 3a133c4, where I removed the `static' attribute from tszRating. I guess the optimizer moves the memory around such that the memory after the string happens to be unimportant. --- c/episodelistview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'c/episodelistview.cpp') diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 3b16a06..ea14b5b 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -443,7 +443,7 @@ r: int iRating; } wchar_t wszRating[3]; - swprintf_s(wszRating, sizeof(wszRating), L"%d", iRating); + swprintf_s(wszRating, sizeof(wszRating)/sizeof(*wszRating), L"%d", iRating); ListView_SetItemText(hWnd, pLvi->iItem, ELVSIRATING, wszRating); } -- cgit v1.2.3