commit c49030b75ad8b8a9f8e7f023b0ee5f9c8c40afdd
parent 555784612b2e3a34315058d3f9454283b6722b91
Author: Devon Gardner <devon@goosur.com>
Date: Fri, 11 Oct 2024 23:43:07 +0000
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.
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git 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;