intelligently avoiding a fatal stack overflow crash?
Posted: Sun Sep 19, 2021 1:12 am
I have a file, X, that logs events and is stored in SPIFFS.
Once every few months, X fills up SPIFFS. When that happens, my software prunes older data from the log.
To do this, I:
- create String S
- copy only the newer half of file X into string S
- dump S into a new file, Y
- then I delete X, using Y as the new log
This code is working great for me, but...
I am concerned that one day for unforeseen reasons my available memory (stack?) could be less than the size of S. Boom, overflow.
Is there a way to ensure S won't overflow the stack? Could I check for free memory, thereby limiting data into S?
I could just appendFile(), byte by byte, from X to Y, without using S. But...
I also serve S in a webpage for users to view the log:
Any advice? I'm not the most skilled of programmers, so dumb it down for me!
Once every few months, X fills up SPIFFS. When that happens, my software prunes older data from the log.
To do this, I:
- create String S
- copy only the newer half of file X into string S
- dump S into a new file, Y
- then I delete X, using Y as the new log
This code is working great for me, but...
I am concerned that one day for unforeseen reasons my available memory (stack?) could be less than the size of S. Boom, overflow.
Is there a way to ensure S won't overflow the stack? Could I check for free memory, thereby limiting data into S?
I could just appendFile(), byte by byte, from X to Y, without using S. But...
I also serve S in a webpage for users to view the log:
Code: Select all
server.send(200, "text/html", S);