1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-08 08:54:34 +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);
char* result = malloc((new_len + 1) * sizeof(char));
if (result == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
if (result == NULL)
return NULL;
const char* q = str;
char* r = result;