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.
This commit is contained in:
Devon Gardner
2024-10-11 23:43:07 +00:00
committed by GitHub
parent 555784612b
commit c49030b75a

View File

@@ -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;