Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/blob.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-10-06 19:14:44 +0400
committerFelix Fietkau <nbd@openwrt.org>2011-10-06 19:14:44 +0400
commit309d7d456f1934a75755504791ad23554a3359d6 (patch)
tree240f34ec11a2539d6ecbaed0deccd30692d8e50e /blob.c
parentf24324c27fe8299b22e983171285eb93d4a74721 (diff)
fill padding bytes when setting raw attribute length
Diffstat (limited to 'blob.c')
-rw-r--r--blob.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/blob.c b/blob.c
index 4bc67a8..e59a6d0 100644
--- 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)
{