Skip to content

Fix undefined behavior in NaN encoding shift#393

Merged
PJK merged 1 commit into
masterfrom
fix-nan-encoding-ub
Feb 8, 2026
Merged

Fix undefined behavior in NaN encoding shift#393
PJK merged 1 commit into
masterfrom
fix-nan-encoding-ub

Conversation

@PJK

@PJK PJK commented Feb 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • 0x7FC0 << 16 in cbor_encode_single() overflows signed int on systems with 32-bit int, which is undefined behavior per the C standard
  • Cast to uint32_t before shifting to make it well-defined
  • The cbor_encode_double() case ((uint64_t)0x7FF8 << 48) was already correctly cast

Test plan

  • All 26 test binaries pass (existing NaN encoding tests cover this path)
  • clang-format clean

🤖 Generated with Claude Code

0x7FC0 << 16 overflows signed int on systems with 32-bit int,
which is undefined behavior. Cast to uint32_t first.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov

codecov Bot commented Feb 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4b025b1) to head (11f313d).
⚠️ Report is 31 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #393   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines         1661      1661           
=========================================
  Hits          1661      1661           

☔ 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.

@PJK
PJK merged commit 375e10b into master Feb 8, 2026
18 checks passed
@PJK
PJK deleted the fix-nan-encoding-ub branch February 8, 2026 18:19
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