diff options
author | nyamatongwe <devnull@localhost> | 2013-04-15 20:10:51 +1000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2013-04-15 20:10:51 +1000 |
commit | 7d7d3d61d6c663aa1a416027ef9a7fc98559ccb0 (patch) | |
tree | c8fd5302c502f4b90cf25906b4cca246e36ab540 /src/RunStyles.cxx | |
parent | afaccacc703e9e436d2bc1c0a8900b8d8c0c7f65 (diff) | |
download | scintilla-mirror-7d7d3d61d6c663aa1a416027ef9a7fc98559ccb0.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.cxx | 36 |
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."); + } + } +} |