From: Lennart Poettering Date: Fri, 11 Aug 2023 09:11:09 +0000 (+0200) Subject: iovec-util: add iovw_isempty() helper X-Git-Tag: v255-rc1~747 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=82ee54b2d88d1a2787c67ef4d73bc73c4047e0c9;p=thirdparty%2Fsystemd.git iovec-util: add iovw_isempty() helper Follow-up for: 3746131aac4798cacf67b60cfc4e2e1c80ec4efb --- diff --git a/src/basic/io-util.c b/src/basic/io-util.c index 21828d7be8e..7f3b092f59d 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -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; diff --git a/src/basic/io-util.h b/src/basic/io-util.h index 6ea2eb20bcf..336c9ce79b0 100644 --- a/src/basic/io-util.h +++ b/src/basic/io-util.h @@ -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); diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c index 515ea2681ee..158d015d89a 100644 --- a/src/journal-remote/journal-remote-write.c +++ b/src/journal-remote/journal-remote-write.c @@ -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",