From 6b0cde0aa2f9c40fafc4114d4950321159fe5da0 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Fri, 28 Jun 2024 14:02:06 +0300 Subject: [PATCH] str_replace.c: do not exit program on `malloc` failure --- c-programming/strings/str_replace.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/c-programming/strings/str_replace.c b/c-programming/strings/str_replace.c index 9a6c658..934a34c 100644 --- a/c-programming/strings/str_replace.c +++ b/c-programming/strings/str_replace.c @@ -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;