1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-12-26 11:30:03 +05:30

str_replace.c: do not exit program on malloc failure

This commit is contained in:
Intel A80486DX2-66 2024-06-28 14:02:06 +03:00
parent 32050ac6a8
commit 6b0cde0aa2
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -47,10 +47,8 @@ char* str_replace(
size_t new_len = strlen(str) + count * (replacement_len - substr_len); size_t new_len = strlen(str) + count * (replacement_len - substr_len);
char* result = malloc((new_len + 1) * sizeof(char)); char* result = malloc((new_len + 1) * sizeof(char));
if (result == NULL) { if (result == NULL)
perror("malloc"); return NULL;
exit(EXIT_FAILURE);
}
const char* q = str; const char* q = str;
char* r = result; char* r = result;