aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/mbyte.c4
-rw-r--r--src/nvim/memline.c5
2 files changed, 5 insertions, 4 deletions
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 1d86eb234c..72f0cec235 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1457,7 +1457,7 @@ void mb_utflen(const char_u *s, size_t len, size_t *codepoints, size_t *codeunit
{
size_t count = 0, extra = 0;
size_t clen;
- for (size_t i = 0; i < len && s[i] != NUL; i += clen) {
+ for (size_t i = 0; i < len; i += clen) {
clen = (size_t)utf_ptr2len_len(s + i, (int)(len - i));
// NB: gets the byte value of invalid sequence bytes.
// we only care whether the char fits in the BMP or not
@@ -1479,7 +1479,7 @@ ssize_t mb_utf_index_to_bytes(const char_u *s, size_t len, size_t index, bool us
if (index == 0) {
return 0;
}
- for (i = 0; i < len && s[i] != NUL; i += clen) {
+ for (i = 0; i < len; i += clen) {
clen = (size_t)utf_ptr2len_len(s + i, (int)(len - i));
// NB: gets the byte value of invalid sequence bytes.
// we only care whether the char fits in the BMP or not
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 13fc2b43ec..6f283701c1 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -2252,8 +2252,9 @@ void ml_add_deleted_len_buf(buf_T *buf, char_u *ptr, ssize_t len)
if (inhibit_delete_count) {
return;
}
- if (len == -1) {
- len = (ssize_t)STRLEN(ptr);
+ ssize_t maxlen = (ssize_t)STRLEN(ptr);
+ if (len == -1 || len > maxlen) {
+ len = maxlen;
}
curbuf->deleted_bytes += (size_t)len + 1;
curbuf->deleted_bytes2 += (size_t)len + 1;