summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-07-30 08:29:31 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-07-30 08:29:31 +0300
commit9b4ce2dbe2353cbbfe98f2819d0f3074d54e6b55 (patch)
tree59a5ea36124557fa5e1bf31a4ed6f7021f9b79cc
parent1d4a75bb3f829e4d54a008753377bbc5af071aac (diff)
InputWidget: Fixed undefined behavior when inserting a newline
-rw-r--r--src/ui/inputwidget.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index c9779ff0..50b12d1f 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -969,11 +969,11 @@ static void textOfLinesWasChanged_InputWidget_(iInputWidget *d, iRangei lineRang
969static void insertRange_InputWidget_(iInputWidget *d, iRangecc range) { 969static void insertRange_InputWidget_(iInputWidget *d, iRangecc range) {
970 iRangecc nextRange = { range.end, range.end }; 970 iRangecc nextRange = { range.end, range.end };
971 const int firstModified = d->cursor.y; 971 const int firstModified = d->cursor.y;
972 for (;; range = nextRange) { 972 for (; !isEmpty_Range(&range); range = nextRange) {
973 /* If there's a newline, we'll need to break and begin a new line. */ 973 /* If there's a newline, we'll need to break and begin a new line. */
974 const char *newline = iStrStrN(range.start, "\n", size_Range(&range)); 974 const char *newline = iStrStrN(range.start, "\n", size_Range(&range));
975 if (newline) { 975 if (newline) {
976 nextRange = (iRangecc){ newline + 1, range.end }; 976 nextRange = (iRangecc){ iMin(newline + 1, range.end), range.end };
977 range.end = newline; 977 range.end = newline;
978 } 978 }
979 iInputLine *line = cursorLine_InputWidget_(d); 979 iInputLine *line = cursorLine_InputWidget_(d);