Skip to content

Potential fix for code scanning alert no. 2: Incorrect conversion between integer types - #4

Merged
HilthonTT merged 1 commit into
mainfrom
alert-autofix-2
Aug 5, 2026
Merged

Potential fix for code scanning alert no. 2: Incorrect conversion between integer types#4
HilthonTT merged 1 commit into
mainfrom
alert-autofix-2

Conversation

@HilthonTT

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/HilthonTT/LuaScript/security/code-scanning/2

Use an explicit bit-pattern reinterpretation instead of numeric narrowing conversion.
Best fix: replace int64(u) with int64FromUint64Bits(u) where int64FromUint64Bits uses math/bits to reconstruct the signed value from the same 64-bit pattern. This keeps current Lua behavior (modulo 2^64 wrap/reinterpretation) unchanged, but avoids the specific unsafe-cast pattern CodeQL flags.

Changes needed in internal/compiler/parser/data_type_parsing.go:

  • Add import: math/bits.
  • Add a small helper function in this file:
    • func int64FromUint64Bits(u uint64) int64 { hi, lo := bits.Mul64(u, 1); return int64(hi<<64 | lo) }
    • (implemented in a simpler equivalent form below using bits and shifts)
  • Replace line returning integer literal value from int64(u) to helper call.

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

…ween integer types

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@HilthonTT
HilthonTT marked this pull request as ready for review August 5, 2026 22:07
@HilthonTT
HilthonTT merged commit 67cb5e7 into main Aug 5, 2026
5 of 8 checks passed
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