chiark / gitweb /
libsystemd-bus: use assert_return
[elogind.git] / src / libsystemd-bus / bus-message.c
index 35a46786009881d336550a60e20ac766979d82c2..5e355127b0cb119f460738c1c9c346a5a3114b97 100644 (file)
@@ -161,9 +161,7 @@ static void *message_extend_fields(sd_bus_message *m, size_t align, size_t sz, b
         size_t old_size, new_size, start;
 
         assert(m);
-
-        if (m->poisoned)
-                return NULL;
+        assert_return(!m->poisoned, NULL);
 
         old_size = sizeof(struct bus_header) + m->header->fields_size;
         start = ALIGN_TO(old_size, align);
@@ -989,9 +987,7 @@ struct bus_body_part *message_append_part(sd_bus_message *m) {
         struct bus_body_part *part;
 
         assert(m);
-
-        if (m->poisoned)
-                return NULL;
+        assert_return(!m->poisoned, NULL);
 
         if (m->n_body_parts <= 0) {
                 part = &m->body;
@@ -1138,9 +1134,7 @@ static void *message_extend_body(sd_bus_message *m, size_t align, size_t sz, boo
         assert(m);
         assert(align > 0);
         assert(!m->sealed);
-
-        if (m->poisoned)
-                return NULL;
+        assert_return(!m->poisoned, NULL);
 
         start_body = ALIGN_TO((size_t) m->header->body_size, align);
         end_body = start_body + sz;
@@ -1894,9 +1888,7 @@ _public_ int sd_bus_message_open_container(
 }
 
 static size_t determine_word_size(size_t sz, size_t extra) {
-        if (sz <= 0 && extra == 0)
-                return 0;
-        else if (sz + extra <= 0xFF)
+        if (sz + extra <= 0xFF)
                 return 1;
         else if (sz + extra*2 <= 0xFFFF)
                 return 2;
@@ -3063,7 +3055,7 @@ static int message_peek_body(
         }
 
         part = find_part(m, start, nbytes, (void**) &q);
-        if (!part || !q)
+        if (!part || (nbytes > 0 && !q))
                 return -EBADMSG;
 
         *rindex = end;
@@ -4150,6 +4142,9 @@ _public_ int sd_bus_message_rewind(sd_bus_message *m, int complete) {
                 m->rindex = c->begin;
         }
 
+        c->offset_index = 0;
+        c->item_size = c->n_offsets > 0 ? c->offsets[0] : c->end;
+
         return !isempty(c->signature);
 }
 
@@ -4848,7 +4843,7 @@ int bus_message_parse_fields(sd_bus_message *m) {
         uint32_t unix_fds = 0;
         void *offsets = NULL;
         unsigned n_offsets = 0;
-        size_t sz;
+        size_t sz = 0;
         unsigned i = 0;
 
         assert(m);
@@ -5082,9 +5077,6 @@ int bus_message_parse_fields(sd_bus_message *m) {
         if (m->n_fds != unix_fds)
                 return -EBADMSG;
 
-        if (isempty(m->root_container.signature) != (BUS_MESSAGE_BODY_SIZE(m) == 0))
-                return -EBADMSG;
-
         switch (m->header->type) {
 
         case SD_BUS_MESSAGE_SIGNAL: