Commit: patch 9.2.0743: string macros silently accept a size of the wrong type

0 views
Skip to first unread message

Christian Brabandt

unread,
1:30 PM (3 hours ago) 1:30 PM
to vim...@googlegroups.com
patch 9.2.0743: string macros silently accept a size of the wrong type

Commit: https://github.com/vim/vim/commit/7f122f9effba51adc107909b8ca4d9b220c2bfaf
Author: Shane Harper <sh...@shaneharper.net>
Date: Sun Jun 28 17:24:04 2026 +0000

patch 9.2.0743: string macros silently accept a size of the wrong type

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 <nor...@anthropic.com>
Signed-off-by: Shane Harper <sh...@shaneharper.net>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/version.c b/src/version.c
index fe47a6e4e..b76dd5b23 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 743,
/**/
742,
/**/
diff --git a/src/vim.h b/src/vim.h
index 0e1cc1d27..c04e5f389 100644
--- 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

/*
Reply all
Reply to author
Forward
0 new messages