fix more instances of uninitialized padding bytes
[project/libubox.git] / blob.c
diff --git a/blob.c b/blob.c
index 4bc67a8..4817fd4 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -67,6 +67,7 @@ blob_add(struct blob_buf *buf, struct blob_attr *pos, int id, int payload)
        }
 
        blob_init(attr, id, payload + sizeof(struct blob_attr));
        }
 
        blob_init(attr, id, payload + sizeof(struct blob_attr));
+       blob_fill_pad(attr);
        return attr;
 }
 
        return attr;
 }
 
@@ -91,6 +92,26 @@ blob_buf_free(struct blob_buf *buf)
        buf->buflen = 0;
 }
 
        buf->buflen = 0;
 }
 
+void
+blob_fill_pad(struct blob_attr *attr)
+{
+       char *buf = (char *) attr;
+       int len = blob_pad_len(attr);
+       int delta = len - blob_raw_len(attr);
+
+       if (delta > 0)
+               memset(buf + len - delta, 0, delta);
+}
+
+void
+blob_set_raw_len(struct blob_attr *attr, unsigned int len)
+{
+       int id = blob_id(attr);
+       len &= BLOB_ATTR_LEN_MASK;
+       len |= (id << BLOB_ATTR_ID_SHIFT) & BLOB_ATTR_ID_MASK;
+       attr->id_len = cpu_to_be32(len);
+}
+
 struct blob_attr *
 blob_new(struct blob_buf *buf, int id, int payload)
 {
 struct blob_attr *
 blob_new(struct blob_buf *buf, int id, int payload)
 {