From 9e8a3287c8fe00b919b7964d2e287e6c7b5f308b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 24 Jul 2022 01:01:06 +0200 Subject: Use std::vector for tracking selected episodes. This also fixes an off-by-one error leading to an out-of-bounds write. --- c/episodelistview.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'c/episodelistview.cpp') diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 4b93587..0cb95d6 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -305,7 +306,7 @@ void EpisodeListView::Update() LVFINDINFO lvfi; extern HWND g_hWndStatus; static TCHAR tszDisp[16], tszEpisode[16]; - static int aEpSel[2048]; + static std::vector vEpSel; lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; @@ -315,15 +316,12 @@ void EpisodeListView::Update() ListView_GetItem(hWnd, &lviTop); /* Save selected episodes. */ - i = 0; + vEpSel.clear(); lvi.mask = LVIF_PARAM; lvi.iItem = -1; - while ((lvi.iItem = ListView_GetNextItem( - hWnd, lvi.iItem, LVNI_SELECTED)) != -1 - && i < 2048) + while ((lvi.iItem = ListView_GetNextItem(hWnd, lvi.iItem, LVNI_SELECTED)) != -1) if (ListView_GetItem(hWnd, &lvi)) - aEpSel[i++] = lvi.lParam; - aEpSel[i] = 0; + vEpSel.push_back(lvi.lParam); iItemMark = ListView_GetSelectionMark(hWnd); /* Save focus. */ @@ -370,9 +368,9 @@ void EpisodeListView::Update() lvfi.flags = LVFI_PARAM; /* Reset selection. */ - for (i = 0; aEpSel[i]; i++) { + for (const int iEpSel : vEpSel) { int iItemSel; - lvfi.lParam = aEpSel[i]; + lvfi.lParam = iEpSel; if ((iItemSel = ListView_FindItem(hWnd, -1, &lvfi)) != -1) ListView_SetItemState(hWnd, iItemSel, LVIS_SELECTED, LVIS_SELECTED); -- cgit v1.2.3