Skip to content

Potential fix for code scanning alert no. 2: Implicit narrowing conversion in compound assignment#7

Merged
hyperpostulate merged 1 commit intomasterfrom
alert-autofix-2
Jan 4, 2026
Merged

Potential fix for code scanning alert no. 2: Implicit narrowing conversion in compound assignment#7
hyperpostulate merged 1 commit intomasterfrom
alert-autofix-2

Conversation

@hyperpostulate
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/hyperpostulate/visual-novel-engine/security/code-scanning/2

In general, to fix implicit narrowing in compound assignments you ensure that both operands have compatible types, either by widening the destination or by making the right-hand side expression match the destination type (without relying on implicit narrowing).

In this specific case, the constraints are stored as Float, and the accumulator relativeTotal is also a float. The problematic line uses constraint.doubleValue(), which promotes the value to double and then implicitly narrows back to float in the += operation. The safest, behavior-preserving fix is to use the float representation directly: call constraint.floatValue() instead of doubleValue(). That way, the addition is performed in float without an implicit narrowing cast, and the effective precision is unchanged because the source data is already a Float.

Concretely:

  • In src/main/java/org/mesutormanli/visualnovel/engine/util/RelativeLayout.java, inside layoutContainerHorizontally, change line 418 from relativeTotal += constraint.doubleValue(); to relativeTotal += constraint.floatValue();.
  • No imports, method additions, or type changes are needed; we only change the accessor used on Float.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…rsion in compound assignment

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@hyperpostulate hyperpostulate marked this pull request as ready for review January 4, 2026 21:01
@hyperpostulate hyperpostulate merged commit 15c2c86 into master Jan 4, 2026
3 checks passed
@hyperpostulate hyperpostulate deleted the alert-autofix-2 branch January 4, 2026 21:17
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