From c49030b75ad8b8a9f8e7f023b0ee5f9c8c40afdd Mon Sep 17 00:00:00 2001 From: Devon Gardner Date: Fri, 11 Oct 2024 23:43:07 +0000 Subject: 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. --- src/nvim/strings.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/strings.c') 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; -- cgit