Skip to content

Replace non-standard Variable-Length Arrays with std::vector in Visualizer - #654

Merged
arybczak merged 1 commit into
ncmpcpp:masterfrom
hyder365:fix/visualizer-vla-to-vector-clean
Jun 25, 2026
Merged

arybczak merged 1 commit into
ncmpcpp:masterfrom
hyder365:fix/visualizer-vla-to-vector-clean

Conversation

@hyder365

@hyder365 hyder365 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

I accidentally included the commit for my other PR in this one, so I had to remake it, sorry.

In Visualizer::update() with stereo mode enabled, the code uses C99 Variable-Length Arrays (VLAs) to allocate audio buffers on the stack:

auto chan_samples = m_rendered_samples.size() / 2;
int16_t buf_left[chan_samples], buf_right[chan_samples];

VLAs aren't part of the C++ standard. Buffer sizes range from ~29 KB per buffer (wave modes) to ~57 KB per buffer (spectrum mode), totaling ~114 KB for both. This approaches or exceeds default stack limits on some platforms (256 KB on Windows, smaller on embedded), potentially causing silent stack overflow crashes.

Using std::vector instead allocates on the heap and is standard C++:

std::vector<int16_t> buf_left(chan_samples), buf_right(chan_samples);

Pass buffers to drawing functions using .data():

(this->*drawStereo)(buf_left.data(), buf_right.data(), chan_samples, half_height);

Also adds #include <vector>.

@arybczak
arybczak merged commit 04f2f43 into ncmpcpp:master Jun 25, 2026
2 checks passed
@arybczak

Copy link
Copy Markdown
Collaborator

Thanks 👍

kda pushed a commit to kda/ncmpcpp that referenced this pull request Sep 8, 2026
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