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.
Runtime allocated data, be it on the stack or heap, is often a problem for memory safety, since large enough data or stacks can overwrite each other or maybe stuff in other memory regions such as .data or .bss, depending on the memory layout (i.e. linker script and program's data).
These allocations' sizes aren't that obvious at compile, and such a memory corruption error could silently exist in the system, but symptoms of it iaren't necessarily obvious or visible (yay for subtle bugs /sarcasm).
In order to make the system more predictable/obvious from compile time (e.g. the static RAM usage vs. how much is left for heap/stack) it is desirable to change stack allocations into statically allocated buffers, use the heap as little as possible, and so on.
The DEBUG* macros are a source of such dynamic allocation on the stack, but given the typical linear execution of the code, it should be safe to reuse a global buffer for the DEBUG messages instead of allocating on the stack.
Even our main objects (WaterSystem, SensorAndPump, WaterSystemSM and the future logging and GeneROMst objects) could be statically allocated and use an init function instead of the constructor to do the runtime intitalization, so the RAM size usage and dynamic needs would be a lot more easier to estimate from compile time data, since only a small amount of objects/data would be on the heap and the stack. This avenue should be explored, too.