Problem: In the popup 'close' option-value completion check, a function pointer (the address of close()) was passed as STRNCMP()'s third argument instead of the string length.
Solution: Pass the length (close_len). (Shane Harper)
The user-visible effect was negligible: ":set completepopup=close:o" offered no completions instead of "on" and "off".
https://github.com/vim/vim/pull/20642
(2 files)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
--- a/src/vim.h +++ b/src/vim.h @@ -1809,7 +1809,7 @@ void *vim_memset(void *, int, size_t); #define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) #define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s), (size_t)(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
Casting to size_t in the macro spoils the compiler type checking.
Removing it might be better?
Or, use a hack? ((size_t)~~(n))
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
There are a number of macros defined in vim.h that have size_t casts. A MUST_BE_INTEGER macro, defined as:
#define MUST_BE_INTEGER(v) (~~(v))
could be used with them so that a compiler can report the use of arguments of the wrong type.
--- a/src/vim.h
+++ b/src/vim.h
@@ -1794,15 +1794,17 @@ void *vim_memset(void *, int, size_t);
#define CLEAR_FIELD(field) vim_memset(&(field), 0, sizeof(field))
#define CLEAR_POINTER(ptr) vim_memset((ptr), 0, sizeof(*(ptr)))
+#define MUST_BE_INTEGER(v) (~~(v))
+
/*
* defines to avoid typecasts from (char_u *) to (char *) and back
* (vim_strchr() and vim_strrchr() are now in strings.c)
*/
#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), (size_t)MUST_BE_INTEGER(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), (size_t)MUST_BE_INTEGER(n))
#ifdef HAVE_STRCASECMP
# define STRICMP(d, s) strcasecmp((char *)(d), (char *)(s))
#else
@@ -1822,12 +1824,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), (size_t)MUST_BE_INTEGER(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), (size_t)MUST_BE_INTEGER(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), (size_t)MUST_BE_INTEGER(n))
# endif
#endif
@@ -1842,7 +1844,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), (size_t)MUST_BE_INTEGER(n))
#ifdef HAVE_STRPBRK
# define vim_strpbrk(s, cs) (char_u *)strpbrk((char *)(s), (char *)(cs))
@@ -1922,7 +1924,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), (size_t)MUST_BE_INTEGER(len))
#endif
/*
@@ -1932,7 +1934,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), (size_t)MUST_BE_INTEGER(n))
#if defined(UNIX) || defined(FEAT_GUI) || defined(VMS) \
|| defined(FEAT_CLIENTSERVER)
@@ -1950,8 +1952,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), (size_t)MUST_BE_INTEGER(count))
+# define vim_write(fd, buf, count) write((fd), (char *)(buf), (size_t)MUST_BE_INTEGER(count))
#endif
/*
Should that be a separate commit?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()