summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-23 13:48:07 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-23 13:48:07 -0500
commit68b77c7a1cde7344702cf1d162e0124498a6b616 (patch)
tree8e0fbc0e6dddaac12c2c37b59d54b12892439ad5 /util.c
parent7448aa490fb843089e5785d5a80f8a07ee50f93a (diff)
got rid of dyn string array - that was unnecessarily complicated
Diffstat (limited to 'util.c')
-rw-r--r--util.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/util.c b/util.c
index 9dcb5ea..bf0f71f 100644
--- a/util.c
+++ b/util.c
@@ -62,9 +62,9 @@ static char *str_dup(char const *src) {
// it is unusual to have a string that long.
#define STRLEN_SAFE_MAX (UINT_MAX >> 2)
-// safer version of strcat. dst_sz includes a null terminator.
-static void str_cat(char *dst, size_t dst_sz, char const *src) {
- size_t dst_len = strlen(dst), src_len = strlen(src);
+// safer version of strncat. dst_sz includes a null terminator.
+static void strn_cat(char *dst, size_t dst_sz, char const *src, size_t src_len) {
+ size_t dst_len = strlen(dst);
// make sure dst_len + src_len + 1 doesn't overflow
if (dst_len > STRLEN_SAFE_MAX || src_len > STRLEN_SAFE_MAX) {
@@ -89,6 +89,11 @@ static void str_cat(char *dst, size_t dst_sz, char const *src) {
}
}
+// safer version of strcat. dst_sz includes a null terminator.
+static void str_cat(char *dst, size_t dst_sz, char const *src) {
+ strn_cat(dst, dst_sz, src, strlen(src));
+}
+
// safer version of strncpy. dst_sz includes a null terminator.
static void str_cpy(char *dst, size_t dst_sz, char const *src) {
size_t srclen = strlen(src);