fix: replace VLA with std::vector in LoRa driver#54
Conversation
727b2d7 to
ae86afe
Compare
PR #54 Review: fix: replace VLA with std::vector in LoRa driverCI StatusSome checks still IN_PROGRESS (Build Firmware, Host Tests, CodeQL). Completed checks passed:
Code Changes Review- uint8_t rx_data[*actual_len + 1];
- read_reg (cmd, rx_data, *actual_len + 1);
- memcpy (data, rx_data + rx_start, *actual_len);
+ std::vector<uint8_t> rx_data (*actual_len + 1);
+ read_reg (cmd, rx_data.data (), *actual_len + 1);
+ memcpy (data, rx_data.data () + rx_start, *actual_len);Issues Found[BEST PRACTICE] [LOW] - Consider heap usage on embedded device The PR title notes this is about avoiding stack pressure, but Positive Observations
No Critical Issues
SummaryNo issues found. Good job! The VLA replacement is a solid fix. CI is still running but no failures detected. The change is minimal, focused, and achieves its goal of eliminating stack-based VLA usage. |
|
Acknowledged the heap usage consideration. std::vector was chosen over static arrays because:
For this specific use case (not in interrupt context), the trade-off is acceptable. If deterministic allocation becomes critical, a static buffer with max size could be used instead. Thanks for the review! |

Summary
Fixes issue #42: VLA (Variable Length Array) in LoRa driver receive()
Problem:
receive()used a C99 VLA:uint8_t rx_data[*actual_len + 1]which is dangerous on embedded systems with limited stack space.Solution: Replaced VLA with
std::vector<uint8_t>which provides dynamic allocation without stack pressure.Changes
firmware/main/lora/sx1262.cpp:#include <vector>uint8_t rx_data[*actual_len + 1]tostd::vector<uint8_t> rx_data(*actual_len + 1)read_regandmemcpycalls to use.data()methodNotes
ESP_ERR_TIMEOUTon timeoutTesting
Build passes for ESP32-S3 target.