]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bus-unit-util: add missing assertions
authorMike Yuan <me@yhndnzj.com>
Tue, 11 Feb 2025 17:13:01 +0000 (18:13 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 12 Feb 2025 14:34:54 +0000 (15:34 +0100)
src/shared/bus-unit-util.c

index ed739503551cac197559fea2eeaf7aa2c2775273..ee09c4f231423497006baa6bb919ed1618d8b773 100644 (file)
@@ -148,9 +148,11 @@ static int bus_append_string(sd_bus_message *m, const char *field, const char *e
 }
 
 static int bus_append_strv(sd_bus_message *m, const char *field, const char *eq, const char *separator, ExtractFlags flags) {
-        const char *p;
         int r;
 
+        assert(m);
+        assert(field);
+
         r = sd_bus_message_open_container(m, 'r', "sv");
         if (r < 0)
                 return bus_log_create_error(r);
@@ -167,16 +169,16 @@ static int bus_append_strv(sd_bus_message *m, const char *field, const char *eq,
         if (r < 0)
                 return bus_log_create_error(r);
 
-        for (p = eq;;) {
+        for (const char *p = eq;;) {
                 _cleanup_free_ char *word = NULL;
 
                 r = extract_first_word(&p, &word, separator, flags);
-                if (r == 0)
-                        break;
                 if (r == -ENOMEM)
                         return log_oom();
                 if (r < 0)
                         return log_error_errno(r, "Invalid syntax: %s", eq);
+                if (r == 0)
+                        break;
 
                 r = sd_bus_message_append_basic(m, 's', word);
                 if (r < 0)