aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/linematch.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
committerJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
commitd5f194ce780c95821a855aca3c19426576d28ae0 (patch)
treed45f461b19f9118ad2bb1f440a7a08973ad18832 /src/nvim/linematch.c
parentc5d770d311841ea5230426cc4c868e8db27300a8 (diff)
parent44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff)
downloadrneovim-rahm.tar.gz
rneovim-rahm.tar.bz2
rneovim-rahm.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309HEADrahm
Diffstat (limited to 'src/nvim/linematch.c')
-rw-r--r--src/nvim/linematch.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/nvim/linematch.c b/src/nvim/linematch.c
index 39dfb8eeb9..79f4c0d692 100644
--- a/src/nvim/linematch.c
+++ b/src/nvim/linematch.c
@@ -3,9 +3,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <string.h>
-#include "nvim/ascii_defs.h"
#include "nvim/linematch.h"
#include "nvim/macros_defs.h"
#include "nvim/memory.h"
@@ -34,12 +32,8 @@ struct diffcmppath_S {
static size_t line_len(const mmfile_t *m)
{
char *s = m->ptr;
- size_t n = (size_t)m->size;
- char *end = strnchr(s, &n, '\n');
- if (end) {
- return (size_t)(end - s);
- }
- return (size_t)m->size;
+ char *end = memchr(s, '\n', (size_t)m->size);
+ return end ? (size_t)(end - s) : (size_t)m->size;
}
#define MATCH_CHAR_MAX_LEN 800
@@ -150,9 +144,9 @@ static int count_n_matched_chars(mmfile_t **sp, const size_t n, bool iwhite)
mmfile_t fastforward_buf_to_lnum(mmfile_t s, linenr_T lnum)
{
for (int i = 0; i < lnum - 1; i++) {
- size_t n = (size_t)s.size;
- s.ptr = strnchr(s.ptr, &n, '\n');
- s.size = (int)n;
+ char *line_end = memchr(s.ptr, '\n', (size_t)s.size);
+ s.size = line_end ? (int)(s.size - (line_end - s.ptr)) : 0;
+ s.ptr = line_end;
if (!s.ptr) {
break;
}