patch 9.1.1467: too many strlen() calls
Problem: too many strlen() calls
Solution: Change expand_env() to return string length
(John Marriott)
This commit does the following changes:
- In expand_env_esc():
- return the length of the returned dst string.
- refactor to remove some calls to STRLEN() and STRCAT()
- add check for out-of-memory condition.
- Change call sites in various source files to use the return value
closes: #17561
Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/findfile.c b/src/findfile.c
index 49def2f..0f5f2dc 100644
--- a/src/findfile.c
+++ b/src/findfile.c
@@ -1820,11 +1820,10 @@
// copy file name into NameBuff, expanding environment variables
save_char = ptr[len];
ptr[len] = NUL;
- expand_env_esc(ptr, NameBuff, MAXPATHL, FALSE, TRUE, NULL);
+ file_to_findlen = expand_env_esc(ptr, NameBuff, MAXPATHL, FALSE, TRUE, NULL);
ptr[len] = save_char;
vim_free(*file_to_find);
- file_to_findlen = STRLEN(NameBuff);
*file_to_find = vim_strnsave(NameBuff, file_to_findlen);
if (*file_to_find == NULL) // out of memory
{