summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-10 12:32:37 -0500
committerpommicket <pommicket@gmail.com>2022-12-10 12:32:37 -0500
commit10ceae41707d6a7aa43d5b8615a47b4f279fbf05 (patch)
tree55ae446197dfcd2d510e1bd185ba9e06a4ddab8e
parentb7cbc84f296024d3a89e4604c1b114e79b4e752e (diff)
parent17e12d6cd6dc769d714991da97db153e7225180e (diff)
Merge branch 'trunk' into lsp
-rw-r--r--util.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/util.c b/util.c
index 4edf601..7bff5c4 100644
--- a/util.c
+++ b/util.c
@@ -69,9 +69,17 @@ static bool streq(char const *a, char const *b) {
return strcmp(a, b) == 0;
}
+static size_t strn_len(const char *src, size_t n) {
+ const char *p = memchr(src, '\0', n);
+ if (p)
+ return (size_t)(p - src);
+ else
+ return n;
+}
+
// duplicates at most n characters from src
static char *strn_dup(char const *src, size_t n) {
- size_t len = strlen(src);
+ size_t len = strn_len(src, n);
if (n > len)
n = len;
char *ret = malloc(n + 1);