Skip to content

Calloc call fix#46

Merged
openwrt-bot merged 4 commits into
openwrt:masterfrom
hauke:calloc-call-fix
May 23, 2026
Merged

Calloc call fix#46
openwrt-bot merged 4 commits into
openwrt:masterfrom
hauke:calloc-call-fix

Conversation

@hauke

@hauke hauke commented May 21, 2026

Copy link
Copy Markdown
Member

Fix the wrong type uses for calloc and also some other type problems.

hauke and others added 4 commits May 23, 2026 02:06
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 <noreply@anthropic.com>
Link: openwrt#46
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
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 <noreply@anthropic.com>
Link: openwrt#46
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
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) <noreply@anthropic.com>
Link: openwrt#46
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
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) <noreply@anthropic.com>
Link: openwrt#46
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
@hauke hauke force-pushed the calloc-call-fix branch from 34c2f08 to 1fe93d2 Compare May 23, 2026 00:07
@openwrt-bot openwrt-bot merged commit 1fe93d2 into openwrt:master May 23, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants