From 7e26a39ec65ed594b5cc5daf721bfc8f672755da Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Wed, 21 May 2025 17:54:43 +0200 Subject: [PATCH] new strops_copy_amount --- strops.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/strops.c b/strops.c index 0be260d..e88802c 100644 --- a/strops.c +++ b/strops.c @@ -39,6 +39,25 @@ char* strops_copy(const char* string) { for(i = 0; i < length; i++) { result[i] = string[i]; } + result[i] = '\0'; + + return result; +} + +char* strops_copy_amount(const char* string, ull_t amount) { + if (!string) { + return 0; + } + if (amount > strops_length(string)) { + return 0; + } + char* result = malloc(amount); + + ull_t i; + for(i = 0; i < amount; i++) { + result[i] = string[i]; + } + result[i] = '\0'; return result; } @@ -234,7 +253,7 @@ char* strops_trim_left_string(const char* string, const char* string_to_remove) for (i = 0; i < strops_length(string_to_remove); i++) { result = strops_remove_at_pos_char(result, 0); } - memcpy(tmp, result, strops_length(string_to_remove)); + tmp = strops_copy_amount(result, strops_length(string_to_remove)); } free(tmp); result = realloc(result, strops_length(result));