refactor: add xmemcpyz() and use it in place of some xstrlcpy() (#28422)

Problem:  Using xstrlcpy() when the exact length of the string to be
          copied is known is not ideal because it requires adding 1 to
          the length and an unnecessary strlen().
Solution: Add xmemcpyz() and use it in place of such xstrlcpy() calls.
This commit is contained in:
zeertzjq
2024-04-20 19:31:00 +08:00
committed by GitHub
parent 4d52b0cf67
commit 0ea38c9a53
23 changed files with 61 additions and 46 deletions

View File

@@ -1989,12 +1989,12 @@ def CheckLanguage(filename, clean_lines, linenum, error):
match = Search(r'\b(strncpy|STRNCPY)\b', line)
if match:
error(filename, linenum, 'runtime/printf', 4,
'Use xstrlcpy or snprintf instead of %s (unless this is from Vim)'
'Use xstrlcpy, xmemcpyz or snprintf instead of %s (unless this is from Vim)'
% match.group(1))
match = Search(r'\b(strcpy)\b', line)
if match:
error(filename, linenum, 'runtime/printf', 4,
'Use xstrlcpy or snprintf instead of %s' % match.group(1))
'Use xstrlcpy, xmemcpyz or snprintf instead of %s' % match.group(1))
match = Search(r'\b(STRNCAT|strncat|strcat|vim_strcat)\b', line)
if match:
error(filename, linenum, 'runtime/printf', 4,