]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0743: string macros silently accept a size of the wrong type v9.2.0743
authorShane Harper <shane@shaneharper.net>
Sun, 28 Jun 2026 17:24:04 +0000 (17:24 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 28 Jun 2026 17:24:04 +0000 (17:24 +0000)
Problem:  Several string and memory wrapper macros cast their size
          argument to size_t although the wrapped function's prototype
          already declares that parameter size_t; such casts silence the
          warning a compiler would otherwise give when a value of the
          wrong type, such as a pointer, is passed as the size.
Solution: Where the wrapped function's prototype already declares the
          parameter size_t, remove the cast so that a size argument of
          the wrong type can be reported at compile time (K.Takata,
          Shane Harper).

From gcc 14 on, -Wint-conversion is an error by default.

With gcc, passing a signed value where size_t is expected triggers
-Wsign-conversion, but the check is off by default and the build already
emits many such warnings.

related: #20642
closes:  #20656

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Shane Harper <shane@shaneharper.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/version.c
src/vim.h

index fe47a6e4e4b14d0284de9184241f3d2bec461f82..b76dd5b23b6ac761c7accead84f0b571e6d1f0eb 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    743,
 /**/
     742,
 /**/
index 0e1cc1d27abca863fc3e539d9502dfd8f0b11f17..c04e5f389cd5fc88b01e3c0e2e06c1a4e66ea21c 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1800,9 +1800,9 @@ void *vim_memset(void *, int, size_t);
  */
 #define STRLEN(s)          strlen((char *)(s))
 #define STRCPY(d, s)       strcpy((char *)(d), (char *)(s))
-#define STRNCPY(d, s, n)    strncpy((char *)(d), (char *)(s), (size_t)(n))
+#define STRNCPY(d, s, n)    strncpy((char *)(d), (char *)(s), (n))
 #define STRCMP(d, s)       strcmp((char *)(d), (char *)(s))
-#define STRNCMP(d, s, n)    strncmp((char *)(d), (char *)(s), (size_t)(n))
+#define STRNCMP(d, s, n)    strncmp((char *)(d), (char *)(s), (n))
 #ifdef HAVE_STRCASECMP
 # define STRICMP(d, s)     strcasecmp((char *)(d), (char *)(s))
 #else
@@ -1822,12 +1822,12 @@ void *vim_memset(void *, int, size_t);
 #define STRMOVE(d, s)      mch_memmove((d), (s), STRLEN(s) + 1)
 
 #ifdef HAVE_STRNCASECMP
-# define STRNICMP(d, s, n)  strncasecmp((char *)(d), (char *)(s), (size_t)(n))
+# define STRNICMP(d, s, n)  strncasecmp((char *)(d), (char *)(s), (n))
 #else
 # ifdef HAVE_STRNICMP
-#  define STRNICMP(d, s, n) strnicmp((char *)(d), (char *)(s), (size_t)(n))
+#  define STRNICMP(d, s, n) strnicmp((char *)(d), (char *)(s), (n))
 # else
-#  define STRNICMP(d, s, n) vim_strnicmp((char *)(d), (char *)(s), (size_t)(n))
+#  define STRNICMP(d, s, n) vim_strnicmp((char *)(d), (char *)(s), (n))
 # endif
 #endif
 
@@ -1842,7 +1842,7 @@ void *vim_memset(void *, int, size_t);
 #define MB_STRNICMP2(d, s, n1, n2)     mb_strnicmp2((char_u *)(d), (char_u *)(s), (n1), (n2))
 
 #define STRCAT(d, s)       strcat((char *)(d), (char *)(s))
-#define STRNCAT(d, s, n)    strncat((char *)(d), (char *)(s), (size_t)(n))
+#define STRNCAT(d, s, n)    strncat((char *)(d), (char *)(s), (n))
 
 #ifdef HAVE_STRPBRK
 # define vim_strpbrk(s, cs) (char_u *)strpbrk((char *)(s), (char *)(cs))
@@ -1922,7 +1922,7 @@ typedef unsigned short disptick_T;        // display tick type
 typedef void       *vim_acl_T;         // dummy to pass an ACL to a function
 
 #ifndef mch_memmove
-# define mch_memmove(to, from, len) memmove((char*)(to), (char*)(from), (size_t)(len))
+# define mch_memmove(to, from, len) memmove((char*)(to), (char*)(from), (len))
 #endif
 
 /*
@@ -1932,7 +1932,7 @@ typedef void          *vim_acl_T;         // dummy to pass an ACL to a function
  * thus it is not 100% accurate!)
  */
 #define fnamecmp(x, y) vim_fnamecmp((char_u *)(x), (char_u *)(y))
-#define fnamencmp(x, y, n) vim_fnamencmp((char_u *)(x), (char_u *)(y), (size_t)(n))
+#define fnamencmp(x, y, n) vim_fnamencmp((char_u *)(x), (char_u *)(y), (n))
 
 #if defined(UNIX) || defined(FEAT_GUI) || defined(VMS) \
        || defined(FEAT_CLIENTSERVER)
@@ -1950,8 +1950,8 @@ typedef void          *vim_acl_T;         // dummy to pass an ACL to a function
 # define vim_read(fd, buf, count)   read((fd), (char *)(buf), (unsigned int)(count))
 # define vim_write(fd, buf, count)  write((fd), (char *)(buf), (unsigned int)(count))
 #else
-# define vim_read(fd, buf, count)   read((fd), (char *)(buf), (size_t) (count))
-# define vim_write(fd, buf, count)  write((fd), (char *)(buf), (size_t) (count))
+# define vim_read(fd, buf, count)   read((fd), (char *)(buf), (count))
+# define vim_write(fd, buf, count)  write((fd), (char *)(buf), (count))
 #endif
 
 /*