]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
iovec-util: add iovw_isempty() helper
authorLennart Poettering <lennart@poettering.net>
Fri, 11 Aug 2023 09:11:09 +0000 (11:11 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 11 Aug 2023 20:51:17 +0000 (21:51 +0100)
Follow-up for: 3746131aac4798cacf67b60cfc4e2e1c80ec4efb

src/basic/io-util.c
src/basic/io-util.h
src/journal-remote/journal-remote-write.c

index 21828d7be8e02ec596a612ace836f925e9736e6c..7f3b092f59d60b63826cb1d1559ca38907771958 100644 (file)
@@ -382,7 +382,7 @@ int iovw_append(struct iovec_wrapper *target, const struct iovec_wrapper *source
 
         /* This duplicates the source and merges it into the target. */
 
-        if (!source || source->count == 0)
+        if (iovw_isempty(source))
                 return 0;
 
         original_count = target->count;
index 6ea2eb20bcf4599c54a13e3d49c907032ad3f6f7..336c9ce79b06e8be78e5ab3bb522f1b5405626ff 100644 (file)
@@ -101,12 +101,19 @@ void iovw_free_contents(struct iovec_wrapper *iovw, bool free_vectors);
 int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len);
 static inline int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len) {
         /* Move data into iovw or free on error */
-        int r = iovw_put(iovw, data, len);
+        int r;
+
+        r = iovw_put(iovw, data, len);
         if (r < 0)
                 free(data);
+
         return r;
 }
 
+static inline bool iovw_isempty(const struct iovec_wrapper *iovw) {
+        return !iovw || iovw->count == 0;
+}
+
 int iovw_put_string_field(struct iovec_wrapper *iovw, const char *field, const char *value);
 int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value);
 void iovw_rebase(struct iovec_wrapper *iovw, char *old, char *new);
index 515ea2681ee6ff823408f0e59fe3d4a8541e7f78..158d015d89a0c14bf5902dc31b59ddb5979e3779 100644 (file)
@@ -88,8 +88,7 @@ int writer_write(Writer *w,
         int r;
 
         assert(w);
-        assert(iovw);
-        assert(iovw->count > 0);
+        assert(!iovw_isempty(iovw));
 
         if (journal_file_rotate_suggested(w->journal->file, 0, LOG_DEBUG)) {
                 log_info("%s: Journal header limits reached or header out-of-date, rotating",