Skip to content

fix: avoid overflow in legacy palette conversion - #123

Open
jakezwang wants to merge 1 commit into
gookit:masterfrom
jakezwang:fix/c256-rgb-intermediate-overflow
Open

jakezwang wants to merge 1 commit into
gookit:masterfrom
jakezwang:fix/c256-rgb-intermediate-overflow

Conversation

@jakezwang

Copy link
Copy Markdown

C256ToRgbV1(231) currently returns [84, 84, 84] instead of [212, 212, 212]: the color-cube multiplication by 85 overflows uint8 before division by two. Perform each channel calculation with int intermediates and convert the completed result to uint8.

The regression checks all 256 inputs, using literal expectations for the existing Linux-derived cube levels, base colors, and grayscale ramp.

Validation on macOS arm64:

  • The new color-cube regression fails before the fix and passes afterward.
  • Full race suites pass on Go 1.18.10, 1.26.6, and 1.27.1; coverage on 1.26.6 is 98% for the main package and 100% for colorp.
  • go vet ./..., go build ./..., and the documented basic, indexed, RGB, tag, and environment examples pass.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 35425717245

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage remained the same at 98.602%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1502
Covered Lines: 1481
Line Coverage: 98.6%
Coverage Strength: 8.56 hits per line

💛 - Coveralls

This branch has not been deployed

No deployments
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.

2 participants