Repository navigation
Fix array out of bounds error in MultiPrinter.getString() - #678
Merged
Merged
Conversation
DavidS-ovm
force-pushed
the
multi-printer-fix
branch
2 times, most recently
from
August 20, 2024 10:14
bf9a2bf to
695c13e
Compare
When `parts` consists of all empty strings, this loop underruns with the
following panic:
```
panic: runtime error: index out of range [-1] [recovered]
panic: runtime error: index out of range [-1]
goroutine 9 [running]:
[...]
panic({0x6b3ee0?, 0xc0000204b0?})
/usr/local/go/src/runtime/panic.go:785 +0x132
github.com/pterm/pterm.(*MultiPrinter).getString(0xc0000d6d00?)
/workspace/pterm/multi_live_printer.go:67 +0x1c6
```
This commit fixes that by checking for the condition and using an empty
string if there is nothing else available.
DavidS-ovm
force-pushed
the
multi-printer-fix
branch
from
August 20, 2024 10:14
695c13e to
4a889b1
Compare
tobias-kuendig
added a commit
to OFFLINE-GmbH/pterm
that referenced
this pull request
Feb 12, 2025
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an array out of bounds error in MultiPrinter.getString() when all parts of the string are empty, and updates the tests accordingly.
- Fix array out of bounds error by checking for empty parts before accessing them.
- Enhance test cases to validate updated behavior for various input buffers.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| multi_live_printer.go | Modified getString() to safely handle empty string parts |
| multi_live_printer_test.go | Added tests for edge cases with empty or newline buffers |
MarvinJWendt
approved these changes
Jun 6, 2025
MarvinJWendt
left a comment
Member
There was a problem hiding this comment.
LGTM! Thanks for contributing 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
partsconsists of all empty strings, this loop underruns with the following panic:This commit fixes that by checking for the condition and using an empty string if there is nothing else available.