diff options
author | Neil <nyamatongwe@gmail.com> | 2015-12-07 11:08:40 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2015-12-07 11:08:40 +1100 |
commit | 18f8f63fb079b084323def219126836f23f5c2b4 (patch) | |
tree | 36a54cbfbc6a72621399e2cbc6923e1f11cc545a | |
parent | 7b5476dae723cc94adeae1460c068aa686f4583b (diff) | |
download | scintilla-mirror-18f8f63fb079b084323def219126836f23f5c2b4.tar.gz |
Prefer StyleIndexAt over StyleAt to avoid problems with out-of-bounds access for
styles > 0x7f.
-rw-r--r-- | src/Document.cxx | 4 | ||||
-rw-r--r-- | src/EditView.cxx | 6 | ||||
-rw-r--r-- | src/Editor.cxx | 8 |
3 files changed, 9 insertions, 9 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index 122ce0f59..b0744a21c 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -2215,7 +2215,7 @@ int Document::BraceMatch(int position, int /*maxReStyle*/) { char chSeek = BraceOpposite(chBrace); if (chSeek == '\0') return - 1; - char styBrace = static_cast<char>(StyleAt(position)); + const int styBrace = StyleIndexAt(position); int direction = -1; if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<') direction = 1; @@ -2223,7 +2223,7 @@ int Document::BraceMatch(int position, int /*maxReStyle*/) { position = NextPosition(position, direction); while ((position >= 0) && (position < Length())) { char chAtPos = CharAt(position); - char styAtPos = static_cast<char>(StyleAt(position)); + const int styAtPos = StyleIndexAt(position); if ((position > GetEndStyled()) || (styAtPos == styBrace)) { if (chAtPos == chBrace) depth++; diff --git a/src/EditView.cxx b/src/EditView.cxx index db6b34fe0..fc98c3d6d 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -376,14 +376,14 @@ void EditView::LayoutLine(const EditModel &model, int line, Surface *surface, co // See if chars, styles, indicators, are all the same bool allSame = true; // Check base line layout - char styleByte = 0; + int styleByte = 0; int numCharsInLine = 0; while (numCharsInLine < lineLength) { int charInDoc = numCharsInLine + posLineStart; char chDoc = model.pdoc->CharAt(charInDoc); - styleByte = model.pdoc->StyleAt(charInDoc); + styleByte = model.pdoc->StyleIndexAt(charInDoc); allSame = allSame && - (ll->styles[numCharsInLine] == static_cast<unsigned char>(styleByte)); + (ll->styles[numCharsInLine] == styleByte); if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseMixed) allSame = allSame && (ll->chars[numCharsInLine] == chDoc); diff --git a/src/Editor.cxx b/src/Editor.cxx index 170f6a931..9c2703ab0 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -764,7 +764,7 @@ bool Editor::RangeContainsProtected(int start, int end) const { end = t; } for (int pos = start; pos < end; pos++) { - if (vs.styles[pdoc->StyleAt(pos)].IsProtected()) + if (vs.styles[pdoc->StyleIndexAt(pos)].IsProtected()) return true; } } @@ -4560,7 +4560,7 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b } bool Editor::PositionIsHotspot(int position) const { - return vs.styles[static_cast<unsigned char>(pdoc->StyleAt(position))].hotspot; + return vs.styles[pdoc->StyleIndexAt(position)].hotspot; } bool Editor::PointIsHotspot(Point pt) { @@ -4994,9 +4994,9 @@ void Editor::StyleToPositionInView(Position pos) { int endWindow = PositionAfterArea(GetClientDrawingRectangle()); if (pos > endWindow) pos = endWindow; - int styleAtEnd = pdoc->StyleAt(pos-1); + const int styleAtEnd = pdoc->StyleIndexAt(pos-1); pdoc->EnsureStyledTo(pos); - if ((endWindow > pos) && (styleAtEnd != pdoc->StyleAt(pos-1))) { + if ((endWindow > pos) && (styleAtEnd != pdoc->StyleIndexAt(pos-1))) { // Style at end of line changed so is multi-line change like starting a comment // so require rest of window to be styled. DiscardOverdraw(); // Prepared bitmaps may be invalid |