blobmsg: make blobmsg_len and blobmsg_data_len return unsigned value
[project/libubox.git] / blobmsg.c
index c2bb7179fb66c15afd468e36e23426c927ea0f46..1a8b783e9ba92b35aff2b1a3ad6912a903b704e1 100644 (file)
--- a/blobmsg.c
+++ b/blobmsg.c
@@ -35,7 +35,8 @@ bool blobmsg_check_attr(const struct blob_attr *attr, bool name)
 {
        const struct blobmsg_hdr *hdr;
        const char *data;
-       int id, len;
+       size_t len;
+       int id;
 
        if (blob_len(attr) < sizeof(struct blobmsg_hdr))
                return false;
@@ -67,7 +68,7 @@ int blobmsg_check_array(const struct blob_attr *attr, int type)
 {
        struct blob_attr *cur;
        bool name;
-       int rem;
+       size_t rem;
        int size = 0;
 
        switch (blobmsg_type(attr)) {
@@ -135,6 +136,8 @@ int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len,
        int i;
 
        memset(tb, 0, policy_len * sizeof(*tb));
+       if (!data || !len)
+               return -EINVAL;
        pslen = alloca(policy_len);
        for (i = 0; i < policy_len; i++) {
                if (!policy[i].name)
@@ -228,8 +231,8 @@ blobmsg_open_nested(struct blob_buf *buf, const char *name, bool array)
        return (void *)offset;
 }
 
-int
-blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format, va_list arg)
+__attribute__((format(printf, 3, 0)))
+int blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format, va_list arg)
 {
        va_list arg2;
        char cbuf;
@@ -249,8 +252,8 @@ blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format, va_l
        return ret;
 }
 
-int
-blobmsg_printf(struct blob_buf *buf, const char *name, const char *format, ...)
+__attribute__((format(printf, 3, 4)))
+int blobmsg_printf(struct blob_buf *buf, const char *name, const char *format, ...)
 {
        va_list ap;
        int ret;