Skip to content

Conversation

DavidS-ovm
Copy link
Contributor

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 DavidS-ovm force-pushed the multi-printer-fix branch 2 times, most recently from bf9a2bf to 695c13e Compare August 20, 2024 10:14
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.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@MarvinJWendt MarvinJWendt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for contributing 🚀

@MarvinJWendt MarvinJWendt merged commit faf819b into pterm:master Jun 6, 2025
1 of 2 checks passed
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