mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-12-26 02:29:50 +05:30
str_replace.c: do not exit program on malloc
failure
This commit is contained in:
parent
32050ac6a8
commit
6b0cde0aa2
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user