diff options
author | Devon Gardner <devon@goosur.com> | 2024-10-11 23:43:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-12 07:43:07 +0800 |
commit | c49030b75ad8b8a9f8e7f023b0ee5f9c8c40afdd (patch) | |
tree | f48e9b47b81d0a546d5e1f8fabd7cd7557179f45 | |
parent | 555784612b2e3a34315058d3f9454283b6722b91 (diff) | |
download | rneovim-c49030b75ad8b8a9f8e7f023b0ee5f9c8c40afdd.tar.gz rneovim-c49030b75ad8b8a9f8e7f023b0ee5f9c8c40afdd.tar.bz2 rneovim-c49030b75ad8b8a9f8e7f023b0ee5f9c8c40afdd.zip |
fix(coverity/497375): f_strpart cast overflow (#30773)
Problem:
Casting long to int introduces risk of overflow.
Solution:
Work with all int64_t (long) rather than casting back and forth.
-rw-r--r-- | src/nvim/strings.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 118abbae6d..2de65391cc 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -2838,10 +2838,10 @@ void f_strpart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (argvars[2].v_type != VAR_UNKNOWN && argvars[3].v_type != VAR_UNKNOWN) { - int off; + int64_t off; // length in characters - for (off = (int)n; off < (int)slen && len > 0; len--) { + for (off = n; off < (int64_t)slen && len > 0; len--) { off += utfc_ptr2len(p + off); } len = off - n; |