From 2af48f9362a459216dea44a81a253e2a8b595ecf Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 26 Sep 2023 13:19:17 +0000 Subject: [PATCH] string: Accept NULL as an empty replacement Signed-off-by: Michael Tremer --- src/libpakfire/string.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/string.c b/src/libpakfire/string.c index db4783aae..3edebef5c 100644 --- a/src/libpakfire/string.c +++ b/src/libpakfire/string.c @@ -127,11 +127,15 @@ char* pakfire_string_replace(const char* s, const char* pattern, const char* rep int r; // Check inputs - if (!s || !pattern || !repl) { + if (!s || !pattern) { errno = EINVAL; return NULL; } + // Accept NULL for repl and replace with an empty string + if (!repl) + repl = ""; + const size_t pattern_length = strlen(pattern); // Walk through the string... -- 2.47.2