diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-24 01:01:06 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-24 01:01:06 +0200 |
commit | 9e8a3287c8fe00b919b7964d2e287e6c7b5f308b (patch) | |
tree | 0770fbfed23b3bec7c8588d4fa0aef0387a77c36 | |
parent | 720b5d820687e9d199686dbe875de1549ccf9a64 (diff) | |
download | EpisodeBrowser-9e8a3287c8fe00b919b7964d2e287e6c7b5f308b.tar.gz |
Use std::vector for tracking selected episodes.
This also fixes an off-by-one error leading to an out-of-bounds write.
-rw-r--r-- | c/episodelistview.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
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 <vector> #include <windows.h> #include <commctrl.h> #include <TCHAR.H> @@ -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<int> 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); |