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));