mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 21:48:35 +00:00
fix: use snprintf instead of sprintf
Clang 14 now reports sprintf as deprecated.
This commit is contained in:

committed by
Lewis Russell

parent
dd0e77d48a
commit
a1bec02c1e
@@ -2702,7 +2702,7 @@ void ex_function(exarg_T *eap)
|
|||||||
// Give the function a sequential number. Can only be used with a
|
// Give the function a sequential number. Can only be used with a
|
||||||
// Funcref!
|
// Funcref!
|
||||||
xfree(name);
|
xfree(name);
|
||||||
sprintf(numbuf, "%d", ++func_nr); // NOLINT(runtime/printf)
|
snprintf(numbuf, sizeof(numbuf), "%d", ++func_nr);
|
||||||
name = xstrdup(numbuf);
|
name = xstrdup(numbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1522,21 +1522,17 @@ int mb_stricmp(const char *s1, const char *s2)
|
|||||||
// 'encoding' has been set to.
|
// 'encoding' has been set to.
|
||||||
void show_utf8(void)
|
void show_utf8(void)
|
||||||
{
|
{
|
||||||
int len;
|
|
||||||
int rlen = 0;
|
|
||||||
char *line;
|
|
||||||
int clen;
|
|
||||||
|
|
||||||
// Get the byte length of the char under the cursor, including composing
|
// Get the byte length of the char under the cursor, including composing
|
||||||
// characters.
|
// characters.
|
||||||
line = get_cursor_pos_ptr();
|
char *line = get_cursor_pos_ptr();
|
||||||
len = utfc_ptr2len(line);
|
int len = utfc_ptr2len(line);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
msg("NUL");
|
msg("NUL");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clen = 0;
|
size_t rlen = 0;
|
||||||
|
int clen = 0;
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (clen == 0) {
|
if (clen == 0) {
|
||||||
// start of (composing) character, get its length
|
// start of (composing) character, get its length
|
||||||
@@ -1546,10 +1542,11 @@ void show_utf8(void)
|
|||||||
}
|
}
|
||||||
clen = utf_ptr2len(line + i);
|
clen = utf_ptr2len(line + i);
|
||||||
}
|
}
|
||||||
sprintf(IObuff + rlen, "%02x ", // NOLINT(runtime/printf)
|
assert(IOSIZE > rlen);
|
||||||
|
snprintf(IObuff + rlen, IOSIZE - rlen, "%02x ",
|
||||||
(line[i] == NL) ? NUL : (uint8_t)line[i]); // NUL is stored as NL
|
(line[i] == NL) ? NUL : (uint8_t)line[i]); // NUL is stored as NL
|
||||||
clen--;
|
clen--;
|
||||||
rlen += (int)strlen(IObuff + rlen);
|
rlen += strlen(IObuff + rlen);
|
||||||
if (rlen > IOSIZE - 20) {
|
if (rlen > IOSIZE - 20) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -2350,13 +2350,13 @@ bool find_decl(char *ptr, size_t len, bool locally, bool thisblock, int flags_ar
|
|||||||
bool incll;
|
bool incll;
|
||||||
int searchflags = flags_arg;
|
int searchflags = flags_arg;
|
||||||
|
|
||||||
pat = xmalloc(len + 7);
|
size_t patlen = len + 7;
|
||||||
|
pat = xmalloc(patlen);
|
||||||
|
|
||||||
// Put "\V" before the pattern to avoid that the special meaning of "."
|
// Put "\V" before the pattern to avoid that the special meaning of "."
|
||||||
// and "~" causes trouble.
|
// and "~" causes trouble.
|
||||||
assert(len <= INT_MAX);
|
assert(patlen <= INT_MAX);
|
||||||
sprintf(pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", // NOLINT(runtime/printf)
|
snprintf(pat, patlen, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", (int)len, ptr);
|
||||||
(int)len, ptr);
|
|
||||||
old_pos = curwin->w_cursor;
|
old_pos = curwin->w_cursor;
|
||||||
save_p_ws = p_ws;
|
save_p_ws = p_ws;
|
||||||
save_p_scs = p_scs;
|
save_p_scs = p_scs;
|
||||||
|
@@ -2472,11 +2472,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
|
|||||||
char buf[MAXLINELEN];
|
char buf[MAXLINELEN];
|
||||||
|
|
||||||
aff_entry->ae_cond = getroom_save(spin, items[4]);
|
aff_entry->ae_cond = getroom_save(spin, items[4]);
|
||||||
if (*items[0] == 'P') {
|
snprintf(buf, sizeof(buf), *items[0] == 'P' ? "^%s" : "%s$", items[4]);
|
||||||
sprintf(buf, "^%s", items[4]); // NOLINT(runtime/printf)
|
|
||||||
} else {
|
|
||||||
sprintf(buf, "%s$", items[4]); // NOLINT(runtime/printf)
|
|
||||||
}
|
|
||||||
aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING + RE_STRICT);
|
aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING + RE_STRICT);
|
||||||
if (aff_entry->ae_prog == NULL) {
|
if (aff_entry->ae_prog == NULL) {
|
||||||
smsg(_("Broken condition in %s line %d: %s"),
|
smsg(_("Broken condition in %s line %d: %s"),
|
||||||
@@ -2520,7 +2516,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
|
|||||||
onecap_copy(items[4], buf, true);
|
onecap_copy(items[4], buf, true);
|
||||||
aff_entry->ae_cond = getroom_save(spin, buf);
|
aff_entry->ae_cond = getroom_save(spin, buf);
|
||||||
if (aff_entry->ae_cond != NULL) {
|
if (aff_entry->ae_cond != NULL) {
|
||||||
sprintf(buf, "^%s", aff_entry->ae_cond); // NOLINT(runtime/printf)
|
snprintf(buf, MAXLINELEN, "^%s", aff_entry->ae_cond);
|
||||||
vim_regfree(aff_entry->ae_prog);
|
vim_regfree(aff_entry->ae_prog);
|
||||||
aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING);
|
aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user