summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-29 17:33:29 -0500
committerpommicket <pommicket@gmail.com>2022-12-29 17:33:29 -0500
commit5f7af06a9085835a3d1ad3a51374c245859d7d97 (patch)
treef8ea4ad4d809334131b479ff8b9c0bd125c45f29 /util.c
parente4aac4859511cb22ed84946eb5510cd7fa14e147 (diff)
fix GCC warnings
Diffstat (limited to 'util.c')
-rw-r--r--util.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/util.c b/util.c
index 93a7f2c..3962069 100644
--- a/util.c
+++ b/util.c
@@ -119,11 +119,14 @@ static bool streq(char const *a, char const *b) {
}
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;
+ const char *p = src;
+ // in C99 and C++11/14, calling memchr with a size larger than
+ // the size of the object is undefined behaviour.
+ // i don't think there's any way of doing this (efficiently) with standard C functions.
+ for (size_t i = 0 ; i < n; ++i, ++p)
+ if (*p == '\0')
+ break;
+ return (size_t)(p - src);
}
// duplicates at most n characters from src