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:
parent
32050ac6a8
commit
6b0cde0aa2
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user