Basically the problem is the inability to write into a char buffer. I call a function which parses a source buffer and put the results into a destination buffer. While the source buffer is fine, the destination buffer appears not writable apart the first 225 bytes, and some garbage characters are left into it. In addition when the function exits the process stops and a Watchdog reset happen.
This is the part of the code where the problem has been triggered:
size_t parseDoc( char* buf, size_t len, char* dest, size_t lendest, AsyncWebServerRequest *request ) {
...(omissis)...
strncat(dest, &buf[lastchunk], i-lastchunk); // copy in output the previous chunk
// code added to debug:
z = strlen(dest);
dest[z] = 'X'; // X not won't be set, actual length is less than the amount of appended bytes
Serial.printf("\nstrlen:%d, free heap:%d, dest*:%x - 1: \n", z, ESP.getFreeHeap(), &dest);
Serial.print(dest);
...(omissis)...
}
The problem seems to be this: the pointer of dest is 3fffdba0h, which apparently put it out of RAM space. Accordingly to what I found here: https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map
user data RAM for applications spans from 3FFE8000h to 3FFFC000h (RAM size 81920 bytes), placing the pointer 3FFFDBA0h clearly out of space.
However the getFreeHeap returns 32928.
The compiler (I use Arduino IDE) says:
Sketch uses 309,578 bytes (29%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 41,124 bytes (50%) of dynamic memory, leaving 40,796 bytes for local variables. Maximum is 81,920 bytes.
so the free heap is apparently roughly at the expected value.
I am stuck, any hint that could help me in pointing out what is going on is really appreciated.
Hardware: NodeMCU 0.9 (ESP12 Module)
Libraries included: ESPAsyncTCP, ESPAsyncWebServer, ESP8266WiFi, ESPDNSserver, ESP8266mDNS