Skip to content

fix: Comparison of narrow type with wide type in loop condition#714

Merged
jprzimba merged 2 commits intomainfrom
alert-autofix-40
May 7, 2026
Merged

fix: Comparison of narrow type with wide type in loop condition#714
jprzimba merged 2 commits intomainfrom
alert-autofix-40

Conversation

@jprzimba
Copy link
Copy Markdown
Collaborator

@jprzimba jprzimba commented May 7, 2026

Use a loop counter type that is at least as wide as message.length()’s type. The best fix is to change the loop index at line 246 from uint8_t to std::string::size_type (or size_t) so both sides of the comparison are width-compatible and cannot wrap at 255.

In a loop condition, comparison of a value of a narrow type with a value of a wide type may result in unexpected behavior if the wider value is sufficiently large (or small). This is because the narrower value may overflow. This can lead to an infinite loop.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@jprzimba jprzimba changed the title Potential fix for code scanning alert no. 40: Comparison of narrow type with wide type in loop condition fix: Comparison of narrow type with wide type in loop condition May 7, 2026
@jprzimba jprzimba marked this pull request as ready for review May 7, 2026 13:48
@jprzimba jprzimba merged commit bbcc0f7 into main May 7, 2026
22 checks passed
@jprzimba jprzimba deleted the alert-autofix-40 branch May 7, 2026 16:42
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