aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/RunStyles.cxx
diff options
context:
space:
mode:
authornyamatongwe <unknown>2013-04-15 20:10:51 +1000
committernyamatongwe <unknown>2013-04-15 20:10:51 +1000
commit11173e2c5c822283e53af1713a42b348f2e504e0 (patch)
tree95a829aa5d9187f6d2369413c7061ddd793fedd0 /src/RunStyles.cxx
parent7d362c38ef421be1d6003b5a2a1bfc560c50b313 (diff)
downloadscintilla-mirror-11173e2c5c822283e53af1713a42b348f2e504e0.tar.gz
RunStyles can be corrupted by filling 0 length ranges and ranges that go past end
so throw std::invalid_argument exceptions for these conditions. Provide a Check method to validate the consistency of a RunStyles and throw std::runtime_error if corruption is detected.
Diffstat (limited to 'src/RunStyles.cxx')
-rw-r--r--src/RunStyles.cxx36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/RunStyles.cxx b/src/RunStyles.cxx
index 9c4e90a66..b74053e75 100644
--- a/src/RunStyles.cxx
+++ b/src/RunStyles.cxx
@@ -9,6 +9,8 @@
#include <stdlib.h>
#include <stdarg.h>
+#include <stdexcept>
+
#include "Platform.h"
#include "Scintilla.h"
@@ -113,7 +115,13 @@ int RunStyles::EndRun(int position) {
}
bool RunStyles::FillRange(int &position, int value, int &fillLength) {
+ if (fillLength <= 0) {
+ throw std::invalid_argument("RunStyles::FillRange <= 0 length.");
+ }
int end = position + fillLength;
+ if (end > Length()) {
+ throw std::invalid_argument("RunStyles::FillRange length goes past end.");
+ }
int runEnd = RunFromPosition(end);
if (styles->ValueAt(runEnd) == value) {
// End already has value so trim range.
@@ -249,3 +257,31 @@ int RunStyles::Find(int value, int start) const {
}
return -1;
}
+
+void RunStyles::Check() {
+ if (Length() < 0) {
+ throw std::runtime_error("RunStyles: Length can not be negative.");
+ }
+ if (starts->Partitions() < 1) {
+ throw std::runtime_error("RunStyles: Must always have 1 or more partitions.");
+ }
+ if (starts->Partitions() != styles->Length()-1) {
+ throw std::runtime_error("RunStyles: Partitions and styles different lengths.");
+ }
+ int start=0;
+ while (start < Length()) {
+ int end = EndRun(start);
+ if (start >= end) {
+ throw std::runtime_error("RunStyles: Partition is 0 length.");
+ }
+ start = end;
+ }
+ if (styles->ValueAt(styles->Length()-1) != 0) {
+ throw std::runtime_error("RunStyles: Unused style at end changed.");
+ }
+ for (int j=1; j<styles->Length()-1; j++) {
+ if (styles->ValueAt(j) == styles->ValueAt(j-1)) {
+ throw std::runtime_error("RunStyles: Style of a partition same as previous.");
+ }
+ }
+}