Skip to content

Commit 6b686c7

Browse files
committed
fix(WeaselUI): limit to subscript range when processing candidates
If candidates.size() is greater than MAX_CANDIDATES_COUNT, only MAX_CANDIDATES_COUNT candidates are processed to prevent display error. Fixes #121
1 parent 67db645 commit 6b686c7

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

WeaselUI/FullScreenLayout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void FullScreenLayout::DoLayout(CDCHandle dc)
5959
_auxiliaryRect.OffsetRect(offsetX, offsetY);
6060
_highlightRect = m_layout->GetHighlightRect();
6161
_highlightRect.OffsetRect(offsetX, offsetY);
62-
for (int i = 0, n = (int)_context.cinfo.candies.size(); i < n; ++i)
62+
for (int i = 0, n = (int)_context.cinfo.candies.size(); i < n && i < MAX_CANDIDATES_COUNT; ++i)
6363
{
6464
_candidateLabelRects[i] = m_layout->GetCandidateLabelRect(i);
6565
_candidateLabelRects[i].OffsetRect(offsetX, offsetY);

WeaselUI/HorizontalLayout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void HorizontalLayout::DoLayout(CDCHandle dc)
4040

4141
/* Candidates */
4242
int w = _style.margin_x, h = 0;
43-
for (size_t i = 0; i < candidates.size(); i++)
43+
for (size_t i = 0; i < candidates.size() && i < MAX_CANDIDATES_COUNT; ++i)
4444
{
4545
if (i > 0)
4646
w += _style.candidate_spacing;

WeaselUI/VerticalLayout.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void VerticalLayout::DoLayout(CDCHandle dc)
4242
int comment_shift_width = 0; /* distance to the left of the candidate text */
4343
int max_candidate_width = 0; /* label + text */
4444
int max_comment_width = 0; /* comment, or none */
45-
for (size_t i = 0; i < candidates.size(); i++)
45+
for (size_t i = 0; i < candidates.size() && i < MAX_CANDIDATES_COUNT; ++i)
4646
{
4747
if (i > 0 )
4848
height += _style.candidate_spacing;
@@ -86,7 +86,7 @@ void VerticalLayout::DoLayout(CDCHandle dc)
8686
width = max(width, max_content_width + 2 * _style.margin_x);
8787

8888
/* Align comments */
89-
for (size_t i = 0; i < candidates.size(); i++)
89+
for (size_t i = 0; i < candidates.size() && i < MAX_CANDIDATES_COUNT; ++i)
9090
_candidateCommentRects[i].OffsetRect(_style.margin_x + comment_shift_width, 0);
9191

9292
if (candidates.size())

WeaselUI/WeaselPanel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ bool WeaselPanel::_DrawCandidates(CDCHandle dc)
215215
const std::vector<Text> &comments(m_ctx.cinfo.comments);
216216
const std::vector<Text> &labels(m_ctx.cinfo.labels);
217217

218-
for (size_t i = 0; i < candidates.size(); i++)
218+
for (size_t i = 0; i < candidates.size() && i < MAX_CANDIDATES_COUNT; ++i)
219219
{
220220
CRect rect;
221221
if (i == m_ctx.cinfo.highlighted)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy