diff options
author | Devon Gardner <devon@goosur.com> | 2024-10-07 23:22:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-07 23:22:09 +0000 |
commit | 60e1862ccba744c4252d30f043bb077c2c657427 (patch) | |
tree | 37ff67663a6ec42535d3ce8259ddacf83ef68685 /src/nvim/linematch.c | |
parent | 5805716ca4dac8f214ed5fd8c3f0a5905a394e8c (diff) | |
download | rneovim-60e1862ccba744c4252d30f043bb077c2c657427.tar.gz rneovim-60e1862ccba744c4252d30f043bb077c2c657427.tar.bz2 rneovim-60e1862ccba744c4252d30f043bb077c2c657427.zip |
fix(coverity/510275): linematch out of bounds access (#30687)
Problem:
Int pointer cast to unsigned long pointer causes potential memory
corruption.
Solution:
Cast and store value first, then pass the new pointer.
Diffstat (limited to 'src/nvim/linematch.c')
-rw-r--r-- | src/nvim/linematch.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/nvim/linematch.c b/src/nvim/linematch.c index 8943e6e8a6..39dfb8eeb9 100644 --- a/src/nvim/linematch.c +++ b/src/nvim/linematch.c @@ -150,7 +150,9 @@ static int count_n_matched_chars(mmfile_t **sp, const size_t n, bool iwhite) mmfile_t fastforward_buf_to_lnum(mmfile_t s, linenr_T lnum) { for (int i = 0; i < lnum - 1; i++) { - s.ptr = strnchr(s.ptr, (size_t *)&s.size, '\n'); + size_t n = (size_t)s.size; + s.ptr = strnchr(s.ptr, &n, '\n'); + s.size = (int)n; if (!s.ptr) { break; } |