iovec-util: add missing assertion
authorMike Yuan <me@yhndnzj.com>
Sun, 10 Dec 2023 16:12:30 +0000 (00:12 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 13 Dec 2023 12:42:05 +0000 (20:42 +0800)
src/basic/iovec-util.c
src/basic/iovec-util.h

index 991889a14eba64d3d07cd2c36296d4efb6b38e8a..64569452832cc46541e7d8558dbf7916d9820d78 100644 (file)
@@ -62,8 +62,10 @@ char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const ch
         return x;
 }
 
-void iovec_array_free(struct iovec *iovec, size_t n) {
-        FOREACH_ARRAY(i, iovec, n)
+void iovec_array_free(struct iovec *iovec, size_t n_iovec) {
+        assert(iovec || n_iovec == 0);
+
+        FOREACH_ARRAY(i, iovec, n_iovec)
                 free(i->iov_base);
 
         free(iovec);
index 39feabd42601214956d90d6657bf7e6142aa3cfe..3f5cdd02e103b4620881a4a93d60bcaf2ecd301b 100644 (file)
@@ -41,4 +41,4 @@ static inline bool iovec_is_set(const struct iovec *iovec) {
 char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value);
 char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const char *field, char *value);
 
-void iovec_array_free(struct iovec *iovec, size_t n);
+void iovec_array_free(struct iovec *iovec, size_t n_iovec);