Thinking aloud here - isn't that a risky bet to assume that because malloc() worked then there won't be a stack overflow ? malloc() could have reused a large free block if you had poked holes into the heap and thus succeeded but that does not mean you won't get a stack overflow.
This article offers a way of checking where the Stack Pointer and the Heap Pointer are relative to one another assuming the memory is always organised like this by GCC
His code should be somewhat valid for common AVR based arduino (somewhat because I would argue that having a function call to establish the stack pointer will not be totally precise since calling a function stores stuff on the stack) so a code like this should give a relative OK view
uint8_t * HeapPointer, * StackPointer; // Globally declaring the Stack and Heap pointers.
void setup() {
Serial.begin(115200); Serial.println();
HeapPointer = (uint8_t *) malloc(1); // small allocation.
free(HeapPointer); // release memory
StackPointer = (uint8_t *)(SP); // Get the Stack Pointer
Serial.print(F("StackPointer\t"));
Serial.println((unsigned int) StackPointer);
Serial.print(F("HeapPointer\t"));
Serial.println((unsigned int) HeapPointer);
}
void loop() {}
On other architectures the code would not really work, SP might be undefined, ESP32 uses multiple types of RAM, it also contains multiple heaps with different capabilities and each RTOS task has its own stack allocated from the heap when the task is created)
side question: I would always suggest to use write for sending out single characters with Serial, would that be the same with a BufferedOutput instance and instead of output.print(':'); I would use output. write(':'); ?
