Any Debug::Print line longer than 45 characters writes past its buffer

Open Beginner friendly
#144 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
embedded-iot

Research direction

Start with the Debug::Print function and its 45-byte static buffer, where the snprintfEx call formats the text. The issue proposes clamping the terminating zero index to the buffer size; check that expression against the return value of snprintfEx before changing anything. Done means a line longer than 45 characters no longer writes past the buffer, and a short line still prints unchanged.

Written by the indexing model from the issue text.

Description

bug
  • What this is: Debug::Print formats text into a 45-byte static buffer with snprintfEx.
    • Problem: snprintfEx keeps counting characters past the buffer size, then writes the closing '\0' at that count. Debug::Print(1,1,"%s", someLongString) with a 100-character result writes a zero byte 55 bytes past the buffer, into other static data.
    • Fix: One line: buffer[writtenChars < size ? writtenChars : size - 1] = '\0';
Dominant language
C++
Stars
90
Forks
5
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ReyeMe/SaturnRingLib

All issues in ReyeMe/SaturnRingLib

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.