0
0
mirror of https://github.com/vim/vim.git synced 2025-07-24 10:45:12 -04:00

patch 9.1.1291: too many strlen() calls in buffer.c

Problem:  too many strlen() calls in buffer.c
Solution: refactor buffer.c and remove strlen() calls
          (John Marriott)

closes: #17063

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
John Marriott 2025-04-10 21:34:19 +02:00 committed by Christian Brabandt
parent 06a41ad084
commit ec032de646
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
4 changed files with 333 additions and 239 deletions

File diff suppressed because it is too large Load Diff

View File

@ -140,6 +140,7 @@ void siemsg(const char *, ...) ATTRIBUTE_COLD ATTRIBUTE_FORMAT_PRINTF(1, 2);
int vim_snprintf_add(char *, size_t, const char *, ...) ATTRIBUTE_FORMAT_PRINTF(3, 4);
int vim_snprintf(char *, size_t, const char *, ...) ATTRIBUTE_FORMAT_PRINTF(3, 4);
size_t vim_snprintf_safelen(char *, size_t, const char *, ...) ATTRIBUTE_FORMAT_PRINTF(3, 4);
int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap)
ATTRIBUTE_FORMAT_PRINTF(3, 0);

View File

@ -2487,6 +2487,33 @@ vim_snprintf(char *str, size_t str_m, const char *fmt, ...)
return str_l;
}
/*
* Like vim_snprintf() except the return value can be safely used to increment a
* buffer length.
* Normal `snprintf()` (and `vim_snprintf()`) returns the number of bytes that
* would have been copied if the destination buffer was large enough.
* This means that you cannot rely on it's return value for the destination
* length because the destination may be shorter than the source. This function
* guarantees the returned length will never be greater than the destination length.
*/
size_t
vim_snprintf_safelen(char *str, size_t str_m, const char *fmt, ...)
{
va_list ap;
int str_l;
va_start(ap, fmt);
str_l = vim_vsnprintf(str, str_m, fmt, ap);
va_end(ap);
if (str_l < 0)
{
*str = NUL;
return 0;
}
return ((size_t)str_l >= str_m) ? str_m - 1 : (size_t)str_l;
}
int
vim_vsnprintf(
char *str,

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1291,
/**/
1290,
/**/