diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-06-02 13:06:48 -0400 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-06-02 13:06:48 -0400 |
| commit | f2ab67a0302e42777fbfc02377fe1e0584d7237d (patch) | |
| tree | 358f2935b7dd9f0bcd4351988eddd9b34d4b388e /src/lib | |
| parent | 17f2b0e475ee66133a0a81124b239842cf5a712f (diff) | |
| download | stasis-f2ab67a0302e42777fbfc02377fe1e0584d7237d.tar.gz | |
Replace string functions
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/core/relocation.c | 3 |
1 files changed, 2 insertions, 1 deletions
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'; |
