Alrighttt I've found the problem! Thanks a lot for helping me everyone... your suggestions have pointed me in the right direction.
It was a combination of problems that lead to the crash on the return line. Due to a hardware buffer overflow (reading CAN messages) the software received wrong values for datalength (myMsg.LEN in the example below).
Code:
for(i=0;i<myMsg.LEN;i++)
{
// printf("B %d) %d %d %d\n", i, myMsg.LEN, strlen(buffer2), strlen(buffer) );
sprintf(buffer2," %3d",myMsg.DATA[i]);
strcat(buffer,buffer2);
}
Normally the myMsg.LEN is 8 at max. Due to the buffer overflow in the hardware, myMsg.LEN was passed into the softaware with a value of around about 600. This caused the for loop to loop 600+ times and therefore the string length of buffer (declared as buffer[512]) was well over the declared size. I've added the following line:
before the for loop and the crashing has stopped!
Finally! Thanks again everyone!
René
Edit: and thanks for your offer KONI, well appreciated.