fill padding bytes when setting raw attribute length
authorFelix Fietkau <nbd@openwrt.org>
Thu, 6 Oct 2011 15:14:44 +0000 (17:14 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 6 Oct 2011 15:14:44 +0000 (17:14 +0200)
blob.c
blob.h

diff --git a/blob.c b/blob.c
index 4bc67a8..e59a6d0 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -91,6 +91,27 @@ blob_buf_free(struct blob_buf *buf)
        buf->buflen = 0;
 }
 
+static 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);
+       blob_fill_pad(attr);
+}
+
 struct blob_attr *
 blob_new(struct blob_buf *buf, int id, int payload)
 {
diff --git a/blob.h b/blob.h
index 7f4a46a..460ea5e 100644 (file)
--- a/blob.h
+++ b/blob.h
@@ -165,15 +165,6 @@ blob_pad_len(const struct blob_attr *attr)
        return len;
 }
 
-static inline 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);
-}
-
 static inline uint8_t
 blob_get_u8(const struct blob_attr *attr)
 {
@@ -213,6 +204,7 @@ blob_next(const struct blob_attr *attr)
        return (struct blob_attr *) ((char *) attr + blob_pad_len(attr));
 }
 
+extern void blob_set_raw_len(struct blob_attr *attr, unsigned int len);
 extern bool blob_attr_equal(const struct blob_attr *a1, const struct blob_attr *a2);
 extern int blob_buf_init(struct blob_buf *buf, int id);
 extern void blob_buf_free(struct blob_buf *buf);