Skip to content

Fix bugs and improve robustness in example code#407

Merged
PJK merged 7 commits intomasterfrom
fix-example-bugs
Feb 16, 2026
Merged

Fix bugs and improve robustness in example code#407
PJK merged 7 commits intomasterfrom
fix-example-bugs

Conversation

@PJK
Copy link
Owner

@PJK PJK commented Feb 15, 2026

Summary

  • Fix negint conversion bug in cbor2cjson.c: unsigned arithmetic on cbor_get_int() (returns uint64_t) caused wraparound; use double arithmetic instead
  • Fix negint encoding bug in cjson2cbor.c: valueint + 1 produced wrong value for the negint64 callback; use (uint64_t)(-1 - valueint) per CBOR encoding rules
  • Fix infinite loop in streaming_parser.c: if cbor_stream_decode returns CBOR_DECODER_ERROR, .read is 0 causing an infinite loop; add error check with break
  • Fix map key buffer in cbor2cjson.c: replace fixed 128-byte buffer with silent truncation with dynamic allocation based on actual key length
  • Replace confusing cbor_move pattern in cbor2cjson.c with explicit get/use/decref for clarity
  • Add fread/sscanf return value checks across all 6 example files
  • Clean up comments in cjson2cbor.c: replace unprofessional/unclear comments

Test plan

  • cmake --build with -DWITH_EXAMPLES=ON succeeds
  • All 26 tests pass
  • clang-format.sh passes

🤖 Generated with Claude Code

PJK and others added 5 commits February 15, 2026 23:15
The default macOS resource class changed to m4pro.medium, which
requires an explicit resource_class in the config. Also bump Xcode
from 16.0.0 to 16.4.0 (latest stable supported on m4pro).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix arithmetic bugs in CBOR negint handling (cbor2cjson.c, cjson2cbor.c),
prevent infinite loop on decode errors (streaming_parser.c), remove fixed-size
key buffer with silent truncation (cbor2cjson.c), and add missing return value
checks for fread/sscanf across all examples.

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

codecov bot commented Feb 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (dfe2297) to head (3b6a86b).
⚠️ Report is 1 commits behind head on master.

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

☔ 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 and others added 2 commits February 16, 2026 00:58
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@PJK PJK merged commit d638af0 into master Feb 16, 2026
18 checks passed
@PJK PJK deleted the fix-example-bugs branch February 16, 2026 00:02
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