]> git.ipfire.org Git - pakfire.git/commitdiff
string: Accept NULL as an empty replacement
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Sep 2023 13:19:17 +0000 (13:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Sep 2023 17:00:55 +0000 (17:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/string.c

index db4783aaeec74fe2dd0d13c37b352fa5c0ee8efe..3edebef5c3a39177ef7982a4b0a3d29029df3d1d 100644 (file)
@@ -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...