Makuna / NeoPixelBus

An Arduino NeoPixel support library supporting a large variety of individually addressable LEDs. Please refer to the Wiki for more details. Please use the GitHub Discussions to ask questions as the GitHub Issues feature is used for bug tracking.
GNU Lesser General Public License v3.0
1.18k stars 264 forks source link

warning: variable length array is used #438

Open Makuna opened 3 years ago

Makuna commented 3 years ago

Describe the bug In NeoPixelBus::_rotateRight and _rotateLeft, it uses a variable length array like

uint8_t temp[rotationCount * T_COLOR_FEATURE::PixelSize];

In GC11+ this is not specifically supported even though it has been around for a while and does seem to work.

If a user supplies a large rotationCount, then the stack will get blown out.

To Reproduce Steps to reproduce the behavior:

  1. Build NeoPixelTest example using warnings with NRF52x (Nano BLE 33)
  2. See warning/error

Expected behavior No Warning/No Error Note, using alloca is considered the standard solution; but this could blow the stack out if the user has a large collection of pixels. Rework code as it really only needs ONE pixel to store the single one while the copy happens.

Makuna commented 3 years ago

interesting research on this topic shows that using alloca is worse and the recommended is VLA like the code has.