aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/linematch.c14
-rw-r--r--src/nvim/strings.c14
2 files changed, 5 insertions, 23 deletions
diff --git a/src/nvim/linematch.c b/src/nvim/linematch.c
index 2627489106..79f4c0d692 100644
--- a/src/nvim/linematch.c
+++ b/src/nvim/linematch.c
@@ -32,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
@@ -148,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;
}
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 7505eaba64..818e67b32d 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -498,20 +498,6 @@ 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)