aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/drawline.c4
-rw-r--r--src/nvim/eval/userfunc.c10
-rw-r--r--src/nvim/input.c5
-rw-r--r--src/nvim/math.c15
-rw-r--r--src/nvim/mbyte.c2
-rw-r--r--src/nvim/normal.c4
-rw-r--r--src/nvim/regexp.c35
7 files changed, 40 insertions, 35 deletions
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index 869fcdf7c0..283f7d9d61 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -1030,7 +1030,9 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
has_decor = decor_redraw_line(wp, lnum - 1, &decor_state);
- decor_providers_invoke_line(wp, lnum - 1, &has_decor);
+ if (!end_fill) {
+ decor_providers_invoke_line(wp, lnum - 1, &has_decor);
+ }
if (has_decor) {
extra_check = true;
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 72559fe9e0..d82d396d4d 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -2578,13 +2578,11 @@ void ex_function(exarg_T *eap)
if (checkforcmd(&arg, "let", 2)) {
int var_count = 0;
int semicolon = 0;
- const char *argend = skip_var_list(arg, &var_count, &semicolon, true);
- if (argend == NULL) {
- // Invalid list assignment: skip to closing bracket.
- argend = find_name_end(arg, NULL, NULL, FNE_INCL_BR);
+ arg = (char *)skip_var_list(arg, &var_count, &semicolon, true);
+ if (arg != NULL) {
+ arg = skipwhite(arg);
}
- arg = skipwhite(argend);
- if (arg[0] == '=' && arg[1] == '<' && arg[2] == '<') {
+ if (arg != NULL && strncmp(arg, "=<<", 3) == 0) {
p = skipwhite(arg + 3);
while (true) {
if (strncmp(p, "trim", 4) == 0) {
diff --git a/src/nvim/input.c b/src/nvim/input.c
index 7667c49452..e14bfe7539 100644
--- a/src/nvim/input.c
+++ b/src/nvim/input.c
@@ -14,6 +14,7 @@
#include "nvim/highlight_defs.h"
#include "nvim/input.h"
#include "nvim/keycodes.h"
+#include "nvim/math.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/message.h"
@@ -21,6 +22,7 @@
#include "nvim/os/input.h"
#include "nvim/state_defs.h"
#include "nvim/ui.h"
+#include "nvim/vim_defs.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "input.c.generated.h" // IWYU pragma: export
@@ -180,10 +182,9 @@ int get_number(int colon, bool *mouse_used)
ui_cursor_goto(msg_row, msg_col);
int c = safe_vgetc();
if (ascii_isdigit(c)) {
- if (n > INT_MAX / 10) {
+ if (vim_append_digit_int(&n, c - '0') == FAIL) {
return 0;
}
- n = n * 10 + c - '0';
msg_putchar(c);
typed++;
} else if (c == K_DEL || c == K_KDEL || c == K_BS || c == Ctrl_H) {
diff --git a/src/nvim/math.c b/src/nvim/math.c
index 2fd9cd6ce7..47a667416c 100644
--- a/src/nvim/math.c
+++ b/src/nvim/math.c
@@ -1,14 +1,16 @@
// uncrustify:off
#include <math.h>
// uncrustify:on
+#include <limits.h>
#include <stdint.h>
#include <string.h>
-#ifdef _MSC_VER
+#ifdef HAVE_BITSCANFORWARD64
# include <intrin.h> // Required for _BitScanForward64
#endif
#include "nvim/math.h"
+#include "nvim/vim_defs.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "math.c.generated.h"
@@ -74,3 +76,14 @@ int xctz(uint64_t x)
return count;
#endif
}
+
+/// For overflow detection, add a digit safely to an int value.
+int vim_append_digit_int(int *value, int digit)
+{
+ int x = *value;
+ if (x > ((INT_MAX - digit) / 10)) {
+ return FAIL;
+ }
+ *value = x * 10 + digit;
+ return OK;
+}
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 0a7bb78102..c7a56209e4 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1387,7 +1387,7 @@ bool mb_isalpha(int a)
return mb_islower(a) || mb_isupper(a);
}
-int utf_strnicmp(const char *s1, const char *s2, size_t n1, size_t n2)
+static int utf_strnicmp(const char *s1, const char *s2, size_t n1, size_t n2)
{
int c1, c2;
char buffer[6];
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index a95965ad6a..b40a11f6d8 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -48,6 +48,7 @@
#include "nvim/mapping.h"
#include "nvim/mark.h"
#include "nvim/mark_defs.h"
+#include "nvim/math.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memline_defs.h"
@@ -2639,11 +2640,10 @@ static bool nv_z_get_count(cmdarg_T *cap, int *nchar_arg)
if (nchar == K_DEL || nchar == K_KDEL) {
n /= 10;
} else if (ascii_isdigit(nchar)) {
- if (n > INT_MAX / 10) {
+ if (vim_append_digit_int(&n, nchar - '0') == FAIL) {
clearopbeep(cap->oap);
break;
}
- n = n * 10 + (nchar - '0');
} else if (nchar == CAR) {
win_setheight(n);
break;
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 32fb086ca6..a81990670a 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -1627,9 +1627,7 @@ static void mb_decompose(int c, int *c1, int *c2, int *c3)
/// Compare two strings, ignore case if rex.reg_ic set.
/// Return 0 if strings match, non-zero otherwise.
-/// Correct the length "*n" when composing characters are ignored
-/// or for utf8 when both utf codepoints are considered equal because of
-/// case-folding but have different length (e.g. 's' and 'ſ')
+/// Correct the length "*n" when composing characters are ignored.
static int cstrncmp(char *s1, char *s2, int *n)
{
int result;
@@ -1637,11 +1635,8 @@ static int cstrncmp(char *s1, char *s2, int *n)
if (!rex.reg_ic) {
result = strncmp(s1, s2, (size_t)(*n));
} else {
- int l2 = utfc_ptr2len(s2);
- result = utf_strnicmp(s1, s2, (size_t)(*n), (size_t)l2);
- if (result == 0 && l2 < *n) {
- *n = l2;
- }
+ assert(*n >= 0);
+ result = mb_strnicmp(s1, s2, (size_t)(*n));
}
// if it failed and it's utf8 and we want to combineignore:
@@ -6495,9 +6490,11 @@ static bool regmatch(uint8_t *scan, const proftime_T *tm, int *timed_out)
}
}
} else {
- if (cstrncmp((char *)opnd, (char *)rex.input, &len) != 0) {
- status = RA_NOMATCH;
- break;
+ for (i = 0; i < len; i++) {
+ if (opnd[i] != rex.input[i]) {
+ status = RA_NOMATCH;
+ break;
+ }
}
}
rex.input += len;
@@ -13849,25 +13846,19 @@ static int skip_to_start(int c, colnr_T *colp)
static int find_match_text(colnr_T *startcol, int regstart, uint8_t *match_text)
{
colnr_T col = *startcol;
- const int regstart_len = utf_char2len(regstart);
+ const int regstart_len = utf_ptr2len((char *)rex.line + col);
while (true) {
bool match = true;
uint8_t *s1 = match_text;
- // skip regstart
- uint8_t *s2 = rex.line + col + regstart_len;
- if (regstart_len > 1
- && utf_char2len(utf_ptr2char((char *)rex.line + col)) != regstart_len) {
- // because of case-folding of the previously matched text, we may need
- // to skip fewer bytes than utf_char2len(regstart)
- s2 = rex.line + col + utf_char2len(utf_fold(regstart));
- }
+ uint8_t *s2 = rex.line + col + regstart_len; // skip regstart
while (*s1) {
int c1_len = utf_ptr2len((char *)s1);
int c1 = utf_ptr2char((char *)s1);
int c2_len = utf_ptr2len((char *)s2);
int c2 = utf_ptr2char((char *)s2);
- if (c1 != c2 && (!rex.reg_ic || utf_fold(c1) != utf_fold(c2))) {
+ if ((c1 != c2 && (!rex.reg_ic || utf_fold(c1) != utf_fold(c2)))
+ || c1_len != c2_len) {
match = false;
break;
}
@@ -15531,7 +15522,7 @@ static int nfa_regexec_both(uint8_t *line, colnr_T startcol, proftime_T *tm, int
// If match_text is set it contains the full text that must match.
// Nothing else to try. Doesn't handle combining chars well.
- if (prog->match_text != NULL && *prog->match_text != NUL && !rex.reg_icombine) {
+ if (prog->match_text != NULL && !rex.reg_icombine) {
retval = find_match_text(&col, prog->regstart, prog->match_text);
if (REG_MULTI) {
rex.reg_mmatch->rmm_matchcol = col;