Skip to content

Potential fix for code scanning alert no. 50: Incorrect conversion between integer types#783

Merged
marle3003 merged 1 commit intomainfrom
alert-autofix-50
Dec 15, 2025
Merged

Potential fix for code scanning alert no. 50: Incorrect conversion between integer types#783
marle3003 merged 1 commit intomainfrom
alert-autofix-50

Conversation

@marle3003
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/marle3003/mokapi/security/code-scanning/50

We should guarantee that only values that fit within the int16 type are assigned to the struct field t.nullable. There are two idiomatic ways to do this in Go:

  1. Parse as a 16-bit integer with strconv.ParseInt(kv[1], 10, 16), then assign after checking error, or
  2. Continue using strconv.Atoi, but add explicit bounds checks against math.MinInt16 and math.MaxInt16 before assignment.

Option 1 is the cleanest and most direct fix; it eliminates the risk of int being a wider type and avoids needing bounds checks. The code should extract the integer value as an int64, check for error, and then assign as int16.

Therefore, in kafka/protocol.go, lines 193–194 should be replaced so that instead of using strconv.Atoi(kv[1]), we use strconv.ParseInt(kv[1], 10, 16); on success, assign as int16(parsed). This preserves the code's logic and safety.

No new imports are required (strconv is already used).


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

…tween integer types

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.89%. Comparing base (539168e) to head (0a21ede).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #783      +/-   ##
==========================================
- Coverage   70.93%   70.89%   -0.04%     
==========================================
  Files         457      457              
  Lines       41302    41302              
==========================================
- Hits        29297    29283      -14     
- Misses       9844     9857      +13     
- Partials     2161     2162       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@marle3003 marle3003 marked this pull request as ready for review December 15, 2025 17:46
@marle3003 marle3003 merged commit fd989c3 into main Dec 15, 2025
10 of 11 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