aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Document.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2015-05-13 15:51:05 +1000
committerNeil <nyamatongwe@gmail.com>2015-05-13 15:51:05 +1000
commita1e62140384ab1025b7befd3442c5805a64882ba (patch)
treedb053a2f84a2b07218d8bccbb5d67d2886c49c81 /src/Document.cxx
parentb57c5c13df4434754f3bf3d39c20e1926578a6da (diff)
downloadscintilla-mirror-a1e62140384ab1025b7befd3442c5805a64882ba.tar.gz
Ensure SCI_POSITIONRELATIVE returns a position clamped into the document range
sensibly. From Mitchell Foral.
Diffstat (limited to 'src/Document.cxx')
-rw-r--r--src/Document.cxx9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 7d34dace1..c25dc84b9 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -767,24 +767,23 @@ bool Document::NextCharacter(int &pos, int moveDir) const {
}
}
-// Return -1 on out-of-bounds
int SCI_METHOD Document::GetRelativePosition(int positionStart, int characterOffset) const {
int pos = positionStart;
if (dbcsCodePage) {
const int increment = (characterOffset > 0) ? 1 : -1;
while (characterOffset != 0) {
const int posNext = NextPosition(pos, increment);
- if (posNext == pos)
+ if (posNext == Length())
+ return posNext;
+ else if (posNext == pos)
return INVALID_POSITION;
pos = posNext;
characterOffset -= increment;
}
} else {
pos = positionStart + characterOffset;
- if ((pos < 0) || (pos > Length()))
- return INVALID_POSITION;
}
- return pos;
+ return ClampPositionIntoDocument(pos);
}
int Document::GetRelativePositionUTF16(int positionStart, int characterOffset) const {