diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-01-10 08:56:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-10 08:56:38 +0100 |
commit | 6d8b5989bc84c0b54cb6804af0851cb3322234b2 (patch) | |
tree | 60e0d4b164ae981c1ed71a333c3fd0df8bee8e54 /src/nvim/cursor.c | |
parent | 57c7e1d4a0d7285d9de5b9035e91f546654268da (diff) | |
parent | fc4ca5bdd8c5a2b37b6efe34a9b32a1bd75c57af (diff) | |
download | rneovim-6d8b5989bc84c0b54cb6804af0851cb3322234b2.tar.gz rneovim-6d8b5989bc84c0b54cb6804af0851cb3322234b2.tar.bz2 rneovim-6d8b5989bc84c0b54cb6804af0851cb3322234b2.zip |
Merge #9472 from justinmk/pvs-warnings2
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r-- | src/nvim/cursor.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index ee1bc6cf31..409eb653a0 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -4,6 +4,7 @@ #include <stdbool.h> #include <inttypes.h> +#include "nvim/assert.h" #include "nvim/cursor.h" #include "nvim/charset.h" #include "nvim/fold.h" @@ -170,7 +171,9 @@ static int coladvance2( if (line[idx] == NUL) { /* Append spaces */ int correct = wcol - col; - char_u *newline = xmallocz((size_t)(idx + correct)); + size_t newline_size; + STRICT_ADD(idx, correct, &newline_size, size_t); + char_u *newline = xmallocz(newline_size); memcpy(newline, line, (size_t)idx); memset(newline + idx, ' ', (size_t)correct); @@ -187,14 +190,17 @@ static int coladvance2( if (-correct > csize) return FAIL; - newline = xmallocz((size_t)(linelen - 1 + csize)); + size_t n; + STRICT_ADD(linelen - 1, csize, &n, size_t); + newline = xmallocz(n); // Copy first idx chars memcpy(newline, line, (size_t)idx); // Replace idx'th char with csize spaces memset(newline + idx, ' ', (size_t)csize); // Copy the rest of the line - memcpy(newline + idx + csize, line + idx + 1, - (size_t)(linelen - idx - 1)); + STRICT_SUB(linelen, idx, &n, size_t); + STRICT_SUB(n, 1, &n, size_t); + memcpy(newline + idx + csize, line + idx + 1, n); ml_replace(pos->lnum, newline, false); changed_bytes(pos->lnum, idx); |