patch 9.1.0959: Coverity complains about type conversion

Commit: 
https://github.com/vim/vim/commit/00d3459ea66438f4bdf3ca37df25c85e864d256a
Author: Yegappan Lakshmanan <yegap...@yahoo.com>
Date:   Wed Dec 25 10:20:51 2024 +0100

    patch 9.1.0959: Coverity complains about type conversion
    
    Problem:  Coverity complains about type conversion
              (after v9.1.0957)
    Solution: use size_t instead of int for file length
              (Yegappan Lakshmanan)
    
    closes: #16297
    
    Signed-off-by: Yegappan Lakshmanan <yegap...@yahoo.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index d516755c4..443883490 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -9700,7 +9700,7 @@ eval_vars(
     char_u     *s;
     char_u     *result;
     char_u     *resultbuf = NULL;
-    int                resultlen;
+    size_t     resultlen;
     buf_T      *buf;
     int                valid = VALID_HEAD + VALID_PATH;    // assume valid 
result
     int                spec_idx;
@@ -9975,12 +9975,12 @@ eval_vars(
                break;
        }
 
-       resultlen = (int)STRLEN(result);        // length of new string
+       resultlen = STRLEN(result);     // length of new string
        if (src[*usedlen] == '<')       // remove the file name extension
        {
            ++*usedlen;
            if ((s = vim_strrchr(result, '.')) != NULL && s >= gettail(result))
-               resultlen = (int)(s - result);
+               resultlen = s - result;
        }
        else if (!skip_mod)
        {
diff --git a/src/filepath.c b/src/filepath.c
index 1ac2f868a..0671d0f2d 100644
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -27,7 +27,7 @@
  * Returns OK on success, FAIL on failure.
  */
     static int
-get_short_pathname(char_u **fnamep, char_u **bufp, int *fnamelen)
+get_short_pathname(char_u **fnamep, char_u **bufp, size_t *fnamelen)
 {
     int                l, len;
     WCHAR      *newbuf;
@@ -80,7 +80,7 @@ get_short_pathname(char_u **fnamep, char_u **bufp, int 
*fnamelen)
     vim_free(wfname);
     vim_free(newbuf);
 
-    *fnamelen = l == 0 ? l : (int)STRLEN(*bufp);
+    *fnamelen = l == 0 ? l : STRLEN(*bufp);
     return OK;
 }
 
@@ -103,13 +103,14 @@ get_short_pathname(char_u **fnamep, char_u **bufp, int 
*fnamelen)
 shortpath_for_invalid_fname(
     char_u     **fname,
     char_u     **bufp,
-    int                *fnamelen)
+    size_t     *fnamelen)
 {
     char_u     *short_fname, *save_fname, *pbuf_unused;
     char_u     *endp, *save_endp;
     char_u     ch;
-    int                old_len, len;
-    int                new_len, sfx_len;
+    size_t     old_len;
+    size_t     len;
+    size_t     new_len, sfx_len;
     int                retval = OK;
 
     // Make a copy
@@ -141,7 +142,7 @@ shortpath_for_invalid_fname(
        ch = *endp;
        *endp = 0;
        short_fname = save_fname;
-       len = (int)STRLEN(short_fname) + 1;
+       len = STRLEN(short_fname) + 1;
        if (get_short_pathname(&short_fname, &pbuf_unused, &len) == FAIL)
        {
            retval = FAIL;
@@ -164,7 +165,7 @@ shortpath_for_invalid_fname(
         */
 
        // Compute the length of the new path.
-       sfx_len = (int)(save_endp - endp) + 1;
+       sfx_len = (save_endp - endp) + 1;
        new_len = len + sfx_len;
 
        *fnamelen = new_len;
@@ -211,9 +212,10 @@ theend:
 shortpath_for_partial(
     char_u     **fnamep,
     char_u     **bufp,
-    int                *fnamelen)
+    size_t     *fnamelen)
 {
-    int                sepcount, len, tflen;
+    int                sepcount;
+    size_t     len, tflen;
     char_u     *p;
     char_u     *pbuf, *tfname;
     int                hasTilde;
@@ -232,7 +234,7 @@ shortpath_for_partial(
     else
        pbuf = tfname = FullName_save(*fnamep, FALSE);
 
-    len = tflen = (int)STRLEN(tfname);
+    len = tflen = STRLEN(tfname);
 
     if (get_short_pathname(&tfname, &pbuf, &len) == FAIL)
        return FAIL;
@@ -273,7 +275,7 @@ shortpath_for_partial(
 
     // Copy in the string - p indexes into tfname - allocated at pbuf
     vim_free(*bufp);
-    *fnamelen = (int)STRLEN(p);
+    *fnamelen = STRLEN(p);
     *bufp = pbuf;
     *fnamep = p;
 
@@ -295,7 +297,7 @@ modify_fname(
     size_t     *usedlen,       // characters after src that are used
     char_u     **fnamep,       // file name so far
     char_u     **bufp,         // buffer for allocated file name or NULL
-    int                *fnamelen)      // length of fnamep
+    size_t     *fnamelen)      // length of fnamep
 {
     int                valid = 0;
     char_u     *tail;
@@ -486,7 +488,7 @@ repeat:
     }
 
     tail = gettail(*fnamep);
-    *fnamelen = (int)STRLEN(*fnamep);
+    *fnamelen = STRLEN(*fnamep);
 
     // ":h" - head, remove "/file_name", can be repeated
     // Don't remove the first "/" or "c:\"
@@ -497,7 +499,7 @@ repeat:
        s = get_past_head(*fnamep);
        while (tail > s && after_pathsep(s, tail))
            MB_PTR_BACK(*fnamep, tail);
-       *fnamelen = (int)(tail - *fnamep);
+       *fnamelen = tail - *fnamep;
 #ifdef VMS
        if (*fnamelen > 0)
            *fnamelen += 1; // the path separator is part of the path
@@ -537,7 +539,7 @@ repeat:
        // Copy the string if it is shortened by :h and when it wasn't copied
        // yet, because we are going to change it in place.  Avoids changing
        // the buffer name for "%:8".
-       if (*fnamelen < (int)STRLEN(*fnamep) || *fnamep == fname_start)
+       if (*fnamelen < STRLEN(*fnamep) || *fnamep == fname_start)
        {
            p = vim_strnsave(*fnamep, *fnamelen);
            if (p == NULL)
@@ -555,7 +557,7 @@ repeat:
        }
        else
        {
-           int         l = *fnamelen;
+           size_t      l = *fnamelen;
 
            // Simple case, already have the full-name.
            // Nearly always shorter, so try first time.
@@ -578,7 +580,7 @@ repeat:
     if (src[*usedlen] == ':' && src[*usedlen + 1] == 't')
     {
        *usedlen += 2;
-       *fnamelen -= (int)(tail - *fnamep);
+       *fnamelen -= tail - *fnamep;
        *fnamep = tail;
     }
 
@@ -601,7 +603,7 @@ repeat:
        {
            if (s > tail)
            {
-               *fnamelen += (int)(*fnamep - (s + 1));
+               *fnamelen += (*fnamep - (s + 1));
                *fnamep = s + 1;
 #ifdef VMS
                // cut version from the extension
@@ -623,7 +625,7 @@ repeat:
            if (limit < tail)
                limit = tail;
            if (s > limit)      // remove one extension
-               *fnamelen = (int)(s - *fnamep);
+               *fnamelen = s - *fnamep;
        }
        *usedlen += 2;
     }
@@ -675,7 +677,7 @@ repeat:
                            if (s != NULL)
                            {
                                *fnamep = s;
-                               *fnamelen = (int)slen;
+                               *fnamelen = slen;
                                vim_free(*bufp);
                                *bufp = s;
                                didit = TRUE;
@@ -706,7 +708,7 @@ repeat:
            return -1;
        vim_free(*bufp);
        *bufp = *fnamep = p;
-       *fnamelen = (int)STRLEN(p);
+       *fnamelen = STRLEN(p);
        *usedlen += 2;
     }
 
@@ -1041,7 +1043,7 @@ f_fnamemodify(typval_T *argvars, typval_T *rettv)
     char_u     *fname;
     char_u     *mods;
     size_t     usedlen = 0;
-    int                len = 0;
+    size_t     len = 0;
     char_u     *fbuf = NULL;
     char_u     buf[NUMBUFLEN];
 
@@ -1056,7 +1058,7 @@ f_fnamemodify(typval_T *argvars, typval_T *rettv)
        fname = NULL;
     else
     {
-       len = (int)STRLEN(fname);
+       len = STRLEN(fname);
        if (mods != NULL && *mods != NUL)
            (void)modify_fname(mods, FALSE, &usedlen, &fname, &fbuf, &len);
     }
@@ -2735,13 +2737,13 @@ home_replace(
     if (homedir_env != NULL && *homedir_env == '~')
     {
        size_t  usedlen = 0;
-       int     flen;
+       size_t  flen;
        char_u  *fbuf = NULL;
 
-       flen = (int)STRLEN(homedir_env);
+       flen = STRLEN(homedir_env);
        (void)modify_fname((char_u *)":p", FALSE, &usedlen,
                                                  &homedir_env, &fbuf, &flen);
-       flen = (int)STRLEN(homedir_env);
+       flen = STRLEN(homedir_env);
        if (flen > 0 && vim_ispathsep(homedir_env[flen - 1]))
            // Remove the trailing / that is added to a directory.
            homedir_env[flen - 1] = NUL;
diff --git a/src/if_cscope.c b/src/if_cscope.c
index 7b6fd926e..6b0f92092 100644
--- a/src/if_cscope.c
+++ b/src/if_cscope.c
@@ -540,7 +540,7 @@ cs_add_common(
     char       *fname2 = NULL;
     char       *ppath = NULL;
     int                i;
-    int                len;
+    size_t     len;
     size_t     usedlen = 0;
     char_u     *fbuf = NULL;
 
@@ -549,7 +549,7 @@ cs_add_common(
        goto add_err;
 
     expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
-    len = (int)STRLEN(fname);
+    len = STRLEN(fname);
     fbuf = (char_u *)fname;
     (void)modify_fname((char_u *)":p", FALSE, &usedlen,
                                              (char_u **)&fname, &fbuf, &len);
diff --git a/src/option.c b/src/option.c
index e4c52bd35..52f996975 100644
--- a/src/option.c
+++ b/src/option.c
@@ -8452,7 +8452,7 @@ vimrc_found(char_u *fname, char_u *envname)
                    }
 #endif
                    else
-                       (void)modify_fname((char_u *)":h", FALSE, &usedlen, &p, 
&fbuf, (int *)&len);
+                       (void)modify_fname((char_u *)":h", FALSE, &usedlen, &p, 
&fbuf, &len);
 
                    if (p != NULL)
                    {
diff --git a/src/proto/filepath.pro b/src/proto/filepath.pro
index 46f51cb36..2979b731f 100644
--- a/src/proto/filepath.pro
+++ b/src/proto/filepath.pro
@@ -1,5 +1,5 @@
 /* filepath.c */
-int modify_fname(char_u *src, int tilde_file, size_t *usedlen, char_u 
**fnamep, char_u **bufp, int *fnamelen);
+int modify_fname(char_u *src, int tilde_file, size_t *usedlen, char_u 
**fnamep, char_u **bufp, size_t *fnamelen);
 void shorten_dir(char_u *str);
 int file_is_readable(char_u *fname);
 void f_chdir(typval_T *argvars, typval_T *rettv);
diff --git a/src/version.c b/src/version.c
index aa5380d35..9f2d5fe3d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    959,
 /**/
     958,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1tQNiT-002Xa9-5e%40256bit.org.

Raspunde prin e-mail lui