aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/strings.c
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-09-26 16:10:11 +0100
committerLewis Russell <lewis6991@gmail.com>2024-09-30 11:51:33 +0100
commitc65646c2474d22948c604168a68f6626a645d1d2 (patch)
treefcf8e49ae06878638e0dacc34e08d7892ccc8524 /src/nvim/strings.c
parent20251be15a4ad3f6e7016450ca3338d52b2f0951 (diff)
downloadrneovim-c65646c2474d22948c604168a68f6626a645d1d2.tar.gz
rneovim-c65646c2474d22948c604168a68f6626a645d1d2.tar.bz2
rneovim-c65646c2474d22948c604168a68f6626a645d1d2.zip
fix(diff): use mmfile_t in linematch
Problem: Linematch used to use strchr to navigate a string, however strchr does not supoprt embedded NULs. Solution: Use `mmfile_t` instead of `char *` in linematch and introduce `strnchr()`. Also remove heap allocations from `matching_char_iwhite()` Fixes: #30505
Diffstat (limited to 'src/nvim/strings.c')
-rw-r--r--src/nvim/strings.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index b7a87ae030..118abbae6d 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -496,6 +496,20 @@ char *vim_strchr(const char *const string, const int c)
}
}
+// Sized version of strchr that can handle embedded NULs.
+// Adjusts n to the new size.
+char *strnchr(const char *p, size_t *n, int c)
+{
+ while (*n > 0) {
+ if (*p == c) {
+ return (char *)p;
+ }
+ p++;
+ (*n)--;
+ }
+ return NULL;
+}
+
// Sort an array of strings.
static int sort_compare(const void *s1, const void *s2)