Skip to content

tc6: fix implicit widening in pointer arithmetic (sync branch)#72

Open
tkummermehr wants to merge 1 commit intomainfrom
static-analysis/implicit-widening-sync
Open

tc6: fix implicit widening in pointer arithmetic (sync branch)#72
tkummermehr wants to merge 1 commit intomainfrom
static-analysis/implicit-widening-sync

Conversation

@tkummermehr
Copy link
Copy Markdown
Collaborator

Summary

Fixes 2 clang-tidy bugprone-implicit-widening-of-multiplication-result warnings in register buffer pointer arithmetic.

Problem

Multiplication of uint16_t num_regs with unsigned constants (4u, 8u) results in unsigned int. When used as array offset in &dst[num_regs * 4u], the result is implicitly widened to size_t, triggering implicit-widening warnings.

Solution

Cast num_regs to size_t before multiplication: (size_t)num_regs * 4u. Explicit cast clarifies the type promotion and silences the warning.

Verification

Affected functions: mk_ctrl_req and mk_secure_ctrl_req. Register arrays are 32-bit fields; num_regs * 4/8 fits safely in size_t. No behavior change.

Closes findings from static-analysis scan.

Cast uint16_t multipliers to size_t before multiplication with unsigned int
constants in pointer offset calculations. Silences clang-tidy warnings about
implicit widening of multiplication results when used as pointer offsets.

Affected: register array pointer advancement in mk_ctrl_req and
mk_secure_ctrl_req functions where (num_regs * 4u) and (num_regs * 8u)
are used as array indices. Multiplication of uint16_t and uint results in
unsigned int, which is implicitly widened to size_t when used as offset.
Explicit cast makes the widening conversion clear.

Finding: clang-tidy/bugprone-implicit-widening-of-multiplication-result at libtc6/src/tc6.c:1053,1094
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.

1 participant