aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/AutoComplete.cxx2
-rw-r--r--src/CaseConvert.cxx8
-rw-r--r--src/Document.cxx18
-rw-r--r--src/Document.h5
-rw-r--r--src/EditModel.cxx7
-rw-r--r--src/SplitVector.h33
6 files changed, 49 insertions, 24 deletions
diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx
index 1447939b7..fec0f20e9 100644
--- a/src/AutoComplete.cxx
+++ b/src/AutoComplete.cxx
@@ -134,7 +134,7 @@ struct Sorter {
indices.push_back(i); // index of last position
}
- bool operator()(int a, int b) {
+ bool operator()(int a, int b) noexcept {
const int lenA = indices[a * 2 + 1] - indices[a * 2];
const int lenB = indices[b * 2 + 1] - indices[b * 2];
const int len = std::min(lenA, lenB);
diff --git a/src/CaseConvert.cxx b/src/CaseConvert.cxx
index 03dbce4e9..fd1bee2c9 100644
--- a/src/CaseConvert.cxx
+++ b/src/CaseConvert.cxx
@@ -588,7 +588,13 @@ class CaseConverter : public ICaseConverter {
}
CharacterConversion(int character_, std::string_view conversion_) noexcept : character(character_) {
assert(conversion_.length() <= maxConversionLength);
- conversion_.copy(conversion.conversion, conversion_.length());
+ try {
+ // This can never fail as std::string_view::copy should only throw
+ // std::out_of_range if pos > size() and pos == 0 here
+ conversion_.copy(conversion.conversion, conversion_.length());
+ } catch (...) {
+ // Ignore any exception
+ }
}
bool operator<(const CharacterConversion &other) const noexcept {
return character < other.character;
diff --git a/src/Document.cxx b/src/Document.cxx
index 70a711028..c20f7beea 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -2477,12 +2477,18 @@ bool Document::AddWatcher(DocWatcher *watcher, void *userData) {
return true;
}
-bool Document::RemoveWatcher(DocWatcher *watcher, void *userData) {
- std::vector<WatcherWithUserData>::iterator it =
- std::find(watchers.begin(), watchers.end(), WatcherWithUserData(watcher, userData));
- if (it != watchers.end()) {
- watchers.erase(it);
- return true;
+bool Document::RemoveWatcher(DocWatcher *watcher, void *userData) noexcept {
+ try {
+ // This can never fail as WatcherWithUserData constructor and == are noexcept
+ // but std::find is not noexcept.
+ std::vector<WatcherWithUserData>::iterator it =
+ std::find(watchers.begin(), watchers.end(), WatcherWithUserData(watcher, userData));
+ if (it != watchers.end()) {
+ watchers.erase(it);
+ return true;
+ }
+ } catch (...) {
+ // Ignore any exception
}
return false;
}
diff --git a/src/Document.h b/src/Document.h
index 5c9840463..09d5841ed 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -489,7 +489,7 @@ public:
void EOLAnnotationClearAll();
bool AddWatcher(DocWatcher *watcher, void *userData);
- bool RemoveWatcher(DocWatcher *watcher, void *userData);
+ bool RemoveWatcher(DocWatcher *watcher, void *userData) noexcept;
CharacterClass WordCharacterClass(unsigned int ch) const;
bool IsWordPartSeparator(unsigned int ch) const;
@@ -525,6 +525,9 @@ public:
UndoGroup &operator=(UndoGroup &&) = delete;
~UndoGroup() {
if (groupNeeded) {
+ // EndUndoAction can throw as it allocates but throw in destructor is fatal.
+ // To fix this UndoHistory should allocate any memory needed by EndUndoAction
+ // beforehand or change EndUndoAction to not require allocation.
pdoc->EndUndoAction();
}
}
diff --git a/src/EditModel.cxx b/src/EditModel.cxx
index e9186a026..5dd3cc87d 100644
--- a/src/EditModel.cxx
+++ b/src/EditModel.cxx
@@ -82,7 +82,12 @@ EditModel::EditModel() : braces{} {
}
EditModel::~EditModel() {
- pdoc->Release();
+ try {
+ // This never throws but isn't marked noexcept for compatibility
+ pdoc->Release();
+ } catch (...) {
+ // Ignore any exception
+ }
pdoc = nullptr;
}
diff --git a/src/SplitVector.h b/src/SplitVector.h
index dc63b4ab6..2b4aed4be 100644
--- a/src/SplitVector.h
+++ b/src/SplitVector.h
@@ -26,20 +26,25 @@ protected:
/// hence be fast.
void GapTo(ptrdiff_t position) noexcept {
if (position != part1Length) {
- if (position < part1Length) {
- // Moving the gap towards start so moving elements towards end
- std::move_backward(
- body.data() + position,
- body.data() + part1Length,
- body.data() + gapLength + part1Length);
- } else { // position > part1Length
- // Moving the gap towards end so moving elements towards start
- std::move(
- body.data() + part1Length + gapLength,
- body.data() + gapLength + position,
- body.data() + part1Length);
+ try {
+ // This can never fail but std::move and std::move_backward are not noexcept.
+ if (position < part1Length) {
+ // Moving the gap towards start so moving elements towards end
+ std::move_backward(
+ body.data() + position,
+ body.data() + part1Length,
+ body.data() + gapLength + part1Length);
+ } else { // position > part1Length
+ // Moving the gap towards end so moving elements towards start
+ std::move(
+ body.data() + part1Length + gapLength,
+ body.data() + gapLength + position,
+ body.data() + part1Length);
+ }
+ part1Length = position;
+ } catch (...) {
+ // Ignore any exception
}
- part1Length = position;
}
}
@@ -280,7 +285,7 @@ public:
}
/// Retrieve a range of elements into an array
- void GetRange(T *buffer, ptrdiff_t position, ptrdiff_t retrieveLength) const noexcept {
+ void GetRange(T *buffer, ptrdiff_t position, ptrdiff_t retrieveLength) const {
// Split into up to 2 ranges, before and after the split then use memcpy on each.
ptrdiff_t range1Length = 0;
if (position < part1Length) {