[OpenWrt-Devel] [PATCH libubox 14/20] blobmsg: make blobmsg_len and blobmsg_data_len return unsigned value

Petr Štetiar ynezz at true.cz
Thu Dec 19 16:58:30 EST 2019


One usually doesn't guard against negative length values in the code.

Signed-off-by: Petr Štetiar <ynezz at true.cz>
---
 blobmsg.c | 3 ++-
 blobmsg.h | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/blobmsg.c b/blobmsg.c
index 97e0c20575ff..1a8b783e9ba9 100644
--- 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;
diff --git a/blobmsg.h b/blobmsg.h
index b06ef597d8c6..0af087890000 100644
--- a/blobmsg.h
+++ b/blobmsg.h
@@ -86,7 +86,7 @@ static inline void *blobmsg_data(const struct blob_attr *attr)
 	return data;
 }
 
-static inline int blobmsg_data_len(const struct blob_attr *attr)
+static inline size_t blobmsg_data_len(const struct blob_attr *attr)
 {
 	uint8_t *start, *end;
 
@@ -99,7 +99,7 @@ static inline int blobmsg_data_len(const struct blob_attr *attr)
 	return blob_len(attr) - (end - start);
 }
 
-static inline int blobmsg_len(const struct blob_attr *attr)
+static inline size_t blobmsg_len(const struct blob_attr *attr)
 {
 	return blobmsg_data_len(attr);
 }

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list