aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval/userfunc.c2
-rw-r--r--src/nvim/lua/treesitter.c18
-rw-r--r--src/nvim/mbyte.c19
-rw-r--r--src/nvim/normal.c8
-rw-r--r--src/nvim/plines.c4
-rw-r--r--src/nvim/spellfile.c8
6 files changed, 23 insertions, 36 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index a52b8d3f18..a5d7ed2758 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -2702,7 +2702,7 @@ void ex_function(exarg_T *eap)
// Give the function a sequential number. Can only be used with a
// Funcref!
xfree(name);
- sprintf(numbuf, "%d", ++func_nr); // NOLINT(runtime/printf)
+ snprintf(numbuf, sizeof(numbuf), "%d", ++func_nr);
name = xstrdup(numbuf);
}
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index 48057b0c65..45fe7f6129 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -1582,25 +1582,19 @@ static void query_err_string(const char *src, int error_offset, TSQueryError err
int error_line_len = 0;
const char *end_str;
- const char *src_tmp = src;
- while ((end_str = strchr(src_tmp, '\n')) != NULL) {
- int line_length = (int)(end_str - src_tmp) + 1;
+ do {
+ const char *src_tmp = src + line_start;
+ end_str = strchr(src_tmp, '\n');
+ int line_length = end_str != NULL ? (int)(end_str - src_tmp) : (int)strlen(src_tmp);
int line_end = line_start + line_length;
if (line_end > error_offset) {
error_line = src_tmp;
error_line_len = line_length;
break;
}
- line_start = line_end;
+ line_start = line_end + 1;
row++;
- src_tmp += line_length;
- }
-
- // Additional check for the last line
- if (line_start <= error_offset) {
- error_line = src_tmp;
- error_line_len = (int)strlen(src_tmp);
- }
+ } while (end_str != NULL);
int column = error_offset - line_start;
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 92e70350bb..fd9efb1387 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1522,21 +1522,17 @@ int mb_stricmp(const char *s1, const char *s2)
// 'encoding' has been set to.
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
// characters.
- line = get_cursor_pos_ptr();
- len = utfc_ptr2len(line);
+ char *line = get_cursor_pos_ptr();
+ int len = utfc_ptr2len(line);
if (len == 0) {
msg("NUL");
return;
}
- clen = 0;
+ size_t rlen = 0;
+ int clen = 0;
for (int i = 0; i < len; i++) {
if (clen == 0) {
// start of (composing) character, get its length
@@ -1546,10 +1542,11 @@ void show_utf8(void)
}
clen = utf_ptr2len(line + i);
}
- sprintf(IObuff + rlen, "%02x ", // NOLINT(runtime/printf)
- (line[i] == NL) ? NUL : (uint8_t)line[i]); // NUL is stored as NL
+ assert(IOSIZE > rlen);
+ snprintf(IObuff + rlen, IOSIZE - rlen, "%02x ",
+ (line[i] == NL) ? NUL : (uint8_t)line[i]); // NUL is stored as NL
clen--;
- rlen += (int)strlen(IObuff + rlen);
+ rlen += strlen(IObuff + rlen);
if (rlen > IOSIZE - 20) {
break;
}
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 0764cbec7a..513fb5b202 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -2350,13 +2350,13 @@ bool find_decl(char *ptr, size_t len, bool locally, bool thisblock, int flags_ar
bool incll;
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 "."
// and "~" causes trouble.
- assert(len <= INT_MAX);
- sprintf(pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", // NOLINT(runtime/printf)
- (int)len, ptr);
+ assert(patlen <= INT_MAX);
+ snprintf(pat, patlen, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", (int)len, ptr);
old_pos = curwin->w_cursor;
save_p_ws = p_ws;
save_p_scs = p_scs;
diff --git a/src/nvim/plines.c b/src/nvim/plines.c
index f59a1754f5..82554c7785 100644
--- a/src/nvim/plines.c
+++ b/src/nvim/plines.c
@@ -216,6 +216,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp)
if (*s == NUL && !has_lcs_eol) {
size = 0; // NUL is not displayed
}
+ bool is_doublewidth = size == 2 && MB_BYTE2LEN((uint8_t)(*s)) > 1;
if (cts->cts_has_virt_text) {
int tab_size = size;
@@ -247,8 +248,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp)
}
}
- if (size == 2 && MB_BYTE2LEN((uint8_t)(*s)) > 1
- && wp->w_p_wrap && in_win_border(wp, vcol)) {
+ if (is_doublewidth && wp->w_p_wrap && in_win_border(wp, vcol + size - 2)) {
// Count the ">" in the last column.
size++;
mb_added = 1;
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index 3337169199..d7dc7fb672 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -2472,11 +2472,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
char buf[MAXLINELEN];
aff_entry->ae_cond = getroom_save(spin, items[4]);
- if (*items[0] == 'P') {
- sprintf(buf, "^%s", items[4]); // NOLINT(runtime/printf)
- } else {
- sprintf(buf, "%s$", items[4]); // NOLINT(runtime/printf)
- }
+ snprintf(buf, sizeof(buf), *items[0] == 'P' ? "^%s" : "%s$", items[4]);
aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING + RE_STRICT);
if (aff_entry->ae_prog == NULL) {
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);
aff_entry->ae_cond = getroom_save(spin, buf);
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);
aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING);
}