tc6: fix implicit widening in pointer arithmetic (sync branch)#72
Open
tkummermehr wants to merge 1 commit intomainfrom
Open
tc6: fix implicit widening in pointer arithmetic (sync branch)#72tkummermehr wants to merge 1 commit intomainfrom
tkummermehr wants to merge 1 commit intomainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 2 clang-tidy
bugprone-implicit-widening-of-multiplication-resultwarnings in register buffer pointer arithmetic.Problem
Multiplication of
uint16_t num_regswith unsigned constants (4u,8u) results inunsigned int. When used as array offset in&dst[num_regs * 4u], the result is implicitly widened tosize_t, triggering implicit-widening warnings.Solution
Cast
num_regstosize_tbefore multiplication:(size_t)num_regs * 4u. Explicit cast clarifies the type promotion and silences the warning.Verification
Affected functions:
mk_ctrl_reqandmk_secure_ctrl_req. Register arrays are 32-bit fields;num_regs * 4/8fits safely insize_t. No behavior change.Closes findings from static-analysis scan.