diff options
| author | Neil <nyamatongwe@gmail.com> | 2026-04-23 10:42:27 +1000 |
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2026-04-23 10:42:27 +1000 |
| commit | fc5004a9e14cfd5c462abca0c8af3cab614aa48d (patch) | |
| tree | 3ee485eec59e9f1547002a8b862c3d25b2a7e306 /src/Document.cxx | |
| parent | ff16983250f077aa2fa1ac1039ad421813fd20f0 (diff) | |
| download | scintilla-mirror-fc5004a9e14cfd5c462abca0c8af3cab614aa48d.tar.gz | |
Add error status SC_STATUS_OUTSIDE_DOCUMENT that is set when operations are
attempted on a position outside the document.
Positions are checked earlier to prevent actions partly succeeding.
This is implemented with a new exception type Failure which should be caught by
platform layer's API handling code to produce a more granular error status.
Diffstat (limited to 'src/Document.cxx')
| -rw-r--r-- | src/Document.cxx | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index f3dac9aaa..289fb6731 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -530,6 +530,13 @@ void SCI_METHOD Document::SetErrorStatus(int status) { } } +void Document::CheckPosition(Sci::Position pos) const { + PLATFORM_ASSERT((pos >= 0) && (pos <= LengthNoExcept())); + if ((pos < 0) || (pos > LengthNoExcept())) { + throw Failure(Status::OutsideDocument); + } +} + Sci_Position SCI_METHOD Document::LineFromPosition(Sci_Position pos) const { return cb.LineFromPosition(pos); } @@ -1485,7 +1492,7 @@ Sci::Position Document::InsertString(Sci::Position position, const char *s, Sci: if (insertLength <= 0) { return 0; } - PLATFORM_ASSERT((position >= 0) && (position <= Length())); + CheckPosition(position); CheckReadOnly(); // Application may change read only state here if (cb.IsReadOnly()) { return 0; |
