]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-string-util: remove several strdupa() calls
authorLuca BRUNO <luca.bruno@coreos.com>
Mon, 24 Oct 2022 12:49:32 +0000 (12:49 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 24 Oct 2022 16:04:12 +0000 (01:04 +0900)
This performs the same semantic transformation as the Coccinelle
script 'strdupa.cocci'.
Somehow the existing semantic patch is not properly triggering on
this 'string_replace_char' test.

src/test/test-string-util.c

index 25ddceb799a5ecd4d8a8091af15af178c0c392e1..d0a2272794c733486ed12c8d0fb83792f58c1ecd 100644 (file)
@@ -1125,11 +1125,11 @@ TEST(strextendf) {
 }
 
 TEST(string_replace_char) {
-        assert_se(streq(string_replace_char(strdupa(""), 'a', 'b'), ""));
-        assert_se(streq(string_replace_char(strdupa("abc"), 'a', 'b'), "bbc"));
-        assert_se(streq(string_replace_char(strdupa("hoge"), 'a', 'b'), "hoge"));
-        assert_se(streq(string_replace_char(strdupa("aaaa"), 'a', 'b'), "bbbb"));
-        assert_se(streq(string_replace_char(strdupa("aaaa"), 'a', '\t'), "\t\t\t\t"));
+        assert_se(streq(string_replace_char(strdupa_safe(""), 'a', 'b'), ""));
+        assert_se(streq(string_replace_char(strdupa_safe("abc"), 'a', 'b'), "bbc"));
+        assert_se(streq(string_replace_char(strdupa_safe("hoge"), 'a', 'b'), "hoge"));
+        assert_se(streq(string_replace_char(strdupa_safe("aaaa"), 'a', 'b'), "bbbb"));
+        assert_se(streq(string_replace_char(strdupa_safe("aaaa"), 'a', '\t'), "\t\t\t\t"));
 }
 
 TEST(strspn_from_end) {