Skip to content

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

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

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

Conversation

@hyperpostulate
Copy link
Copy Markdown
Owner

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

In general, this kind of issue is fixed by ensuring both sides of the compound assignment have compatible types, so no implicit narrowing cast is required. Either the destination variable is widened (e.g., floatdouble), or the right-hand side expression is computed in the narrower type (e.g., doublefloat), typically by using the appropriate accessor (floatValue()) or an explicit cast.

For this specific case, the clearest, behaviour-preserving fix is to keep relativeTotal as a float (since constraints are Floats), and avoid using doubleValue(). Instead, use constraint.floatValue() so that both operands of += are float. That avoids any implicit doublefloat narrowing, and there is no functional change: a Float’s floatValue() and doubleValue() hold the same underlying precision, just represented in a wider type for doubleValue().

Concretely, in src/main/java/org/mesutormanli/visualnovel/engine/util/RelativeLayout.java, in the layoutContainerVertically method, change line 510 from relativeTotal += constraint.doubleValue(); to relativeTotal += constraint.floatValue();. No imports or additional methods are required.

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 20:58
@hyperpostulate hyperpostulate merged commit b1b0023 into master Jan 4, 2026
3 checks passed
@hyperpostulate hyperpostulate deleted the alert-autofix-3 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