From 19e88cc41288478ae01d9246065ad319f9ca4e8e Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Thu, 21 May 2026 21:29:42 +0200 Subject: [PATCH 1/4] json_script: use size_t for calloc_a() length argument json_script_file_from_blobmsg() passed name_len, a plain int, as a chunk size to calloc_a(). __calloc_a() reads chunk sizes as size_t through varargs, so on LP64 systems va_arg(ap, size_t) reads 8 bytes where only 4 were pushed. Widen name_len to size_t. Co-Authored-By: Claude Opus 4.7 Link: https://github.com/openwrt/libubox/pull/46 Signed-off-by: Hauke Mehrtens --- json_script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_script.c b/json_script.c index de7e546..d33462b 100644 --- a/json_script.c +++ b/json_script.c @@ -39,7 +39,7 @@ json_script_file_from_blobmsg(const char *name, void *data, int len) { struct json_script_file *f; char *new_name; - int name_len = 0; + size_t name_len = 0; if (name) name_len = strlen(name) + 1; From 9afc710534817a3066e42542b3ef07ccd1e903a7 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Thu, 21 May 2026 21:29:46 +0200 Subject: [PATCH 2/4] udebug-remote: pass size_t to calloc_a() udebug_remote_buf_snapshot() passed data_size, a uint32_t, as a chunk size to calloc_a(). __calloc_a() reads chunk sizes as size_t through varargs, so on LP64 systems va_arg(ap, size_t) reads 8 bytes where only 4 were pushed. Cast data_size to size_t at the call site. Co-Authored-By: Claude Opus 4.7 Link: https://github.com/openwrt/libubox/pull/46 Signed-off-by: Hauke Mehrtens --- udebug-remote.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/udebug-remote.c b/udebug-remote.c index 7fa0b3a..1d6f0fc 100644 --- a/udebug-remote.c +++ b/udebug-remote.c @@ -237,7 +237,7 @@ udebug_remote_buf_snapshot(struct udebug_remote_buf *rb) s = calloc_a(sizeof(*s), &ptr_buf, ptr_size * sizeof(*ptr_buf), - &data_buf, data_size); + &data_buf, (size_t)data_size); s->data = memcpy(data_buf, udebug_buf_ptr(&rb->buf, data_start), data_size); s->data_size = data_size; From 73a21977c52a47f9a0ccb6116553083b118d0084 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Thu, 21 May 2026 22:18:16 +0200 Subject: [PATCH 3/4] treewide: use size_t for length variables to avoid implicit narrowing Several local length variables stored the result of size_t-returning functions (strlen, blob_pad_len, blob_raw_len, array_list_length) in an int, which GCC's -Wconversion reports as a potentially value-changing narrowing conversion. Widen these variables (and one static helper and one static function parameter) to size_t where the int type was not needed: - avl-cmp: _min() and the memcmp() length in avl_blobcmp() - blob: len/delta in blob_fill_pad() - blobmsg_json: loop counters in blobmsg_add_array() and the length parameter of blobmsg_format_json_list() - jshn: loop counters in add_json_array() udebug_entry_printf() stored the int result of udebug_entry_vprintf() in a size_t; use int there instead. No functional change. Co-Authored-By: Claude Opus 4.7 (1M context) Link: https://github.com/openwrt/libubox/pull/46 Signed-off-by: Hauke Mehrtens --- avl-cmp.c | 4 ++-- blob.c | 4 ++-- blobmsg_json.c | 8 ++++---- jshn.c | 6 +++--- udebug.c | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/avl-cmp.c b/avl-cmp.c index 39c1f5b..70b092f 100644 --- a/avl-cmp.c +++ b/avl-cmp.c @@ -17,7 +17,7 @@ #include "avl-cmp.h" #include "blob.h" -static inline int _min(int v1, int v2) +static inline size_t _min(size_t v1, size_t v2) { return v1 < v2 ? v1 : v2; } @@ -31,7 +31,7 @@ avl_strcmp(const void *k1, const void *k2, void *ptr) int avl_blobcmp(const void *k1, const void *k2, void *ptr) { - int len = _min(blob_raw_len(k1), blob_raw_len(k2)); + size_t len = _min(blob_raw_len(k1), blob_raw_len(k2)); return memcmp(k1, k2, len); } diff --git a/blob.c b/blob.c index 93321ed..529e08c 100644 --- a/blob.c +++ b/blob.c @@ -125,8 +125,8 @@ 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); + size_t len = blob_pad_len(attr); + size_t delta = len - blob_raw_len(attr); if (delta > 0) memset(buf + len - delta, 0, delta); diff --git a/blobmsg_json.c b/blobmsg_json.c index 04bb9a1..4865cd3 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -30,7 +30,7 @@ bool blobmsg_add_object(struct blob_buf *b, json_object *obj) static bool blobmsg_add_array(struct blob_buf *b, struct array_list *a) { - int i, len; + size_t i, len; for (i = 0, len = array_list_length(a); i < len; i++) { if (!blobmsg_add_json_element(b, NULL, array_list_get_idx(a, i))) @@ -228,14 +228,14 @@ static void blobmsg_format_string(struct strbuf *s, const char *str) blobmsg_puts(s, "\"", 1); } -static void blobmsg_format_json_list(struct strbuf *s, struct blob_attr *attr, int len, bool array); +static void blobmsg_format_json_list(struct strbuf *s, struct blob_attr *attr, size_t len, bool array); static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, bool without_name, bool head) { const char *data_str; char buf[317]; void *data; - int len; + size_t len; if (!blobmsg_check_attr(attr, false)) return; @@ -289,7 +289,7 @@ static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo blobmsg_puts(s, data_str, strlen(data_str)); } -static void blobmsg_format_json_list(struct strbuf *s, struct blob_attr *attr, int len, bool array) +static void blobmsg_format_json_list(struct strbuf *s, struct blob_attr *attr, size_t len, bool array) { struct blob_attr *pos; bool first = true; diff --git a/jshn.c b/jshn.c index 4b947e1..bd34a2c 100644 --- a/jshn.c +++ b/jshn.c @@ -58,12 +58,12 @@ static int add_json_object(json_object *obj) static int add_json_array(struct array_list *a) { - char seq[12]; - int i, len; + char seq[21]; + size_t i, len; int ret; for (i = 0, len = array_list_length(a); i < len; i++) { - snprintf(seq, sizeof(seq), "%d", i); + snprintf(seq, sizeof(seq), "%zu", i); ret = add_json_element(seq, array_list_get_idx(a, i)); if (ret) return ret; diff --git a/udebug.c b/udebug.c index 1b43f69..09e97ef 100644 --- a/udebug.c +++ b/udebug.c @@ -595,7 +595,7 @@ void udebug_entry_set_length(struct udebug_buf *buf, uint16_t len) int udebug_entry_printf(struct udebug_buf *buf, const char *fmt, ...) { va_list ap; - size_t ret; + int ret; va_start(ap, fmt); ret = udebug_entry_vprintf(buf, fmt, ap); From 1fe93d2fefb213ec987763e7e94ce5eaa757bfc3 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Thu, 21 May 2026 22:30:38 +0200 Subject: [PATCH 4/4] blob, udebug-remote: silence -Wconversion warnings in trivial cases blob.h is included by nearly every translation unit, so the conversions in its inline helpers were reported over and over: - blob_id(): hold the masked/shifted id in an unsigned int; the function already returns unsigned int - blob_pad_len(): use size_t for the length (matching blob_raw_len()) and an unsigned mask, instead of unsigned int and a signed ~mask - blob_get_int8/16/32/64(): make the intended reinterpretation of the unsigned value as signed explicit with a cast udebug-remote: rb->pcap_iface is a uint32_t, so assign ~0U instead of the signed ~0 (GCC flagged the latter as changing -1 to 4294967295). No functional change. Co-Authored-By: Claude Opus 4.7 (1M context) Link: https://github.com/openwrt/libubox/pull/46 Signed-off-by: Hauke Mehrtens --- blob.h | 14 +++++++------- udebug-remote.c | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/blob.h b/blob.h index 13bc7cc..95b0852 100644 --- a/blob.h +++ b/blob.h @@ -83,7 +83,7 @@ blob_data(const struct blob_attr *attr) static inline unsigned int blob_id(const struct blob_attr *attr) { - int id = (be32_to_cpu(attr->id_len) & BLOB_ATTR_ID_MASK) >> BLOB_ATTR_ID_SHIFT; + unsigned int id = (be32_to_cpu(attr->id_len) & BLOB_ATTR_ID_MASK) >> BLOB_ATTR_ID_SHIFT; return id; } @@ -117,8 +117,8 @@ blob_raw_len(const struct blob_attr *attr) static inline size_t blob_pad_len(const struct blob_attr *attr) { - unsigned int len = blob_raw_len(attr); - len = (len + BLOB_ATTR_ALIGN - 1) & ~(BLOB_ATTR_ALIGN - 1); + size_t len = blob_raw_len(attr); + len = (len + BLOB_ATTR_ALIGN - 1) & ~(size_t)(BLOB_ATTR_ALIGN - 1); return len; } @@ -154,25 +154,25 @@ blob_get_u64(const struct blob_attr *attr) static inline int8_t blob_get_int8(const struct blob_attr *attr) { - return blob_get_u8(attr); + return (int8_t)blob_get_u8(attr); } static inline int16_t blob_get_int16(const struct blob_attr *attr) { - return blob_get_u16(attr); + return (int16_t)blob_get_u16(attr); } static inline int32_t blob_get_int32(const struct blob_attr *attr) { - return blob_get_u32(attr); + return (int32_t)blob_get_u32(attr); } static inline int64_t blob_get_int64(const struct blob_attr *attr) { - return blob_get_u64(attr); + return (int64_t)blob_get_u64(attr); } static inline const char * diff --git a/udebug-remote.c b/udebug-remote.c index 1d6f0fc..8894908 100644 --- a/udebug-remote.c +++ b/udebug-remote.c @@ -66,7 +66,7 @@ int udebug_remote_buf_map(struct udebug *ctx, struct udebug_remote_buf *rb, uint return -1; } - rb->pcap_iface = ~0; + rb->pcap_iface = ~0U; rb->node.key = key; avl_insert(&ctx->remote_rings, &rb->node); @@ -82,7 +82,7 @@ void udebug_remote_buf_unmap(struct udebug *ctx, struct udebug_remote_buf *rb) udebug_buf_free(&rb->buf); rb->poll = 0; rb->node.key = NULL; - rb->pcap_iface = ~0; + rb->pcap_iface = ~0U; } int udebug_remote_buf_set_poll(struct udebug *ctx, struct udebug_remote_buf *rb, bool val)