From f2ab67a0302e42777fbfc02377fe1e0584d7237d Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 2 Jun 2026 13:06:48 -0400 Subject: Replace string functions --- src/lib/core/relocation.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/core/relocation.c b/src/lib/core/relocation.c index 8204101..6afd198 100644 --- a/src/lib/core/relocation.c +++ b/src/lib/core/relocation.c @@ -10,7 +10,7 @@ * ~~~{.c} * size_t str_maxlen = 100; * char *str = calloc(str_maxlen, sizeof(char)); - * strncpy(str, "This are a test.", str_maxlen - 1); + * safe_strncpy(str, "This are a test.", str_maxlen); * if (replace_text(str, "are", "is")) { * fprintf(stderr, "string replacement failed\n"); * exit(1); @@ -84,6 +84,7 @@ int replace_text(char *original, const char *target, const char *replacement, un // truncate whatever remains of the original buffer memset(original + buffer_len, 0, original_len - buffer_len); } + // replace original with contents of buffer strncpy(original, buffer, buffer_len + 1); original[buffer_len] = '\0'; -- cgit