Skip to content

Commit

Permalink
fix(WeaselUI): limit to subscript range when processing candidates
Browse files Browse the repository at this point in the history
If candidates.size() is greater than MAX_CANDIDATES_COUNT, only MAX_CANDIDATES_COUNT
candidates are processed to prevent display error.

Fixes #121
  • Loading branch information
Prcuvu committed Feb 28, 2018
1 parent 67db645 commit 6b686c7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion WeaselUI/FullScreenLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void FullScreenLayout::DoLayout(CDCHandle dc)
_auxiliaryRect.OffsetRect(offsetX, offsetY);
_highlightRect = m_layout->GetHighlightRect();
_highlightRect.OffsetRect(offsetX, offsetY);
for (int i = 0, n = (int)_context.cinfo.candies.size(); i < n; ++i)
for (int i = 0, n = (int)_context.cinfo.candies.size(); i < n && i < MAX_CANDIDATES_COUNT; ++i)
{
_candidateLabelRects[i] = m_layout->GetCandidateLabelRect(i);
_candidateLabelRects[i].OffsetRect(offsetX, offsetY);
Expand Down
2 changes: 1 addition & 1 deletion WeaselUI/HorizontalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void HorizontalLayout::DoLayout(CDCHandle dc)

/* Candidates */
int w = _style.margin_x, h = 0;
for (size_t i = 0; i < candidates.size(); i++)
for (size_t i = 0; i < candidates.size() && i < MAX_CANDIDATES_COUNT; ++i)
{
if (i > 0)
w += _style.candidate_spacing;
Expand Down
4 changes: 2 additions & 2 deletions WeaselUI/VerticalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void VerticalLayout::DoLayout(CDCHandle dc)
int comment_shift_width = 0; /* distance to the left of the candidate text */
int max_candidate_width = 0; /* label + text */
int max_comment_width = 0; /* comment, or none */
for (size_t i = 0; i < candidates.size(); i++)
for (size_t i = 0; i < candidates.size() && i < MAX_CANDIDATES_COUNT; ++i)
{
if (i > 0 )
height += _style.candidate_spacing;
Expand Down Expand Up @@ -86,7 +86,7 @@ void VerticalLayout::DoLayout(CDCHandle dc)
width = max(width, max_content_width + 2 * _style.margin_x);

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

if (candidates.size())
Expand Down
2 changes: 1 addition & 1 deletion WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ bool WeaselPanel::_DrawCandidates(CDCHandle dc)
const std::vector<Text> &comments(m_ctx.cinfo.comments);
const std::vector<Text> &labels(m_ctx.cinfo.labels);

for (size_t i = 0; i < candidates.size(); i++)
for (size_t i = 0; i < candidates.size() && i < MAX_CANDIDATES_COUNT; ++i)
{
CRect rect;
if (i == m_ctx.cinfo.highlighted)
Expand Down

0 comments on commit 6b686c7

Please sign in to comment.