refactor: replace sprintf with snprintf #15794

This commit is contained in:
dundargoc 2021-09-26 16:53:51 +02:00 committed by GitHub
parent 68d6ff8802
commit c273eb3100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -8807,9 +8807,9 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
char_u *newval = xmalloc(newval_len);
if (eap->force_bin == FORCE_BIN) {
sprintf((char *)newval, " ++bin");
snprintf((char *)newval, newval_len, " ++bin");
} else if (eap->force_bin == FORCE_NOBIN) {
sprintf((char *)newval, " ++nobin");
snprintf((char *)newval, newval_len, " ++nobin");
} else {
*newval = NUL;
}

View File

@ -5549,8 +5549,9 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname,
if (add_help_tags
|| path_full_compare((char_u *)"$VIMRUNTIME/doc",
dir, false, true) == kEqualFiles) {
s = xmalloc(18 + STRLEN(tagfname));
sprintf((char *)s, "help-tags\t%s\t1\n", tagfname);
size_t s_len = 18 + STRLEN(tagfname);
s = xmalloc(s_len);
snprintf((char *)s, s_len, "help-tags\t%s\t1\n", tagfname);
GA_APPEND(char_u *, &ga, s);
}
@ -5611,10 +5612,11 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname,
&& (vim_strchr((char_u *)" \t\n\r", s[1]) != NULL
|| s[1] == '\0')) {
*p2 = '\0';
++p1;
s = xmalloc((p2 - p1) + STRLEN(fname) + 2);
p1++;
size_t s_len= (p2 - p1) + STRLEN(fname) + 2;
s = xmalloc(s_len);
GA_APPEND(char_u *, &ga, s);
sprintf((char *)s, "%s\t%s", p1, fname);
snprintf((char *)s, s_len, "%s\t%s", p1, fname);
// find next '*'
p2 = vim_strchr(p2 + 1, '*');