>From 83c7104c645441cab1433446b5e1a3db0a16aacd Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 11 Apr 2020 12:20:59 +0200 Subject: [PATCH] Use xmalloc, not malloc. * lib/pk-utils.c (pk_str_replace): Use xmalloc, not malloc. Don't return NULL. --- ChangeLog | 6 ++++++ lib/pk-utils.c | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7928c4a..be30f91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-04-11 Bruno Haible + + Use xmalloc, not malloc. + * lib/pk-utils.c (pk_str_replace): Use xmalloc, not malloc. Don't return + NULL. + 2020-04-11 Jose E. Marchesi * lib/pvm.h (PVM_OK): Define. diff --git a/lib/pk-utils.c b/lib/pk-utils.c index 69292b7..6ccf061 100644 --- a/lib/pk-utils.c +++ b/lib/pk-utils.c @@ -161,7 +161,6 @@ pk_str_concat(const char *s0, ...) /* Replace all occurrences of SEARCH within IN by REPLACE. * Return IN when SEARCH was not found, else * return a new allocated string with the replaced sequences. - * Return NULL on allocation failure. */ char * pk_str_replace (const char *in, const char *search, const char *replace) @@ -181,9 +180,7 @@ pk_str_replace (const char *in, const char *search, const char *replace) size_t replace_len = strlen (replace); size_t in_len = strlen (in); - d = out = malloc (in_len + (replace_len - search_len) * num + 1); - if (!out) - return NULL; + d = out = xmalloc (in_len + (replace_len - search_len) * num + 1); for (s = in; (e = strstr (s, search)); s = e + search_len) { -- 2.7.4