From fc5004a9e14cfd5c462abca0c8af3cab614aa48d Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 23 Apr 2026 10:42:27 +1000 Subject: 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. --- src/Document.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/Document.cxx') 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; -- cgit v1.2.3