From: Michael Tremer Date: Tue, 26 Sep 2023 13:19:17 +0000 (+0000) Subject: string: Accept NULL as an empty replacement X-Git-Tag: 0.9.30~1637 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2af48f9362a459216dea44a81a253e2a8b595ecf;p=pakfire.git string: Accept NULL as an empty replacement Signed-off-by: Michael Tremer --- 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...