Ethernet read stack overflow

It is funny because it is very hard to find anything information about stackoverflows on the arduino because of the similarly named website. :slight_smile:

But here is my problem:
I have a function that reads the client data then proceeds to parse it. Initially I wrote my own multibyte read function but just changed to the built in one. Same problem occurs.
Upon leaving the function the arduino crashes and resets to the setup routine.

I think that it has to do with some garbage on the end of the incoming data. If I read less than the 22 incoming bytes then it does not crash until I attempt to read it again. The incoming bytes can change so I can ignore what are garbage now because it will be data later on(the data also has a variable length). All of the data is numeric ascii with spaces.

Any thoughts or solutions would be great.

I removed all of the parsing because it is commented out in my code.

int DecodeHeader(void)
{
//int iReturn = 0;
//const UN_FEP_HEADER *punHdr;

int iIncomingBytes = 0;
byte byteHeaderBuffer[MAX_INPUT_PACKET_SIZE];
char acDataReport[MAX_INPUT_PACKET_SIZE];

iIncomingBytes = client.read(byteHeaderBuffer, MAX_INPUT_PACKET_SIZE);
sprintf(acDataReport,"Byte Count: %d\nOutput String: %s",iIncomingBytes,byteHeaderBuffer);
Serial.println(acDataReport);

return 0;
}

I think it has to do with my large data structs. I know there is a 2k limit on ram. Does anyone have examples of large(2k) structs stored in flash?
I have a 600 byte struct stored using PROGMEM but when I memset it to 0. It crashes and just constantly dump garbage out the serial port.

Thanks,

Impossible to guess the actual memory use unless you post a complete sketch. Have you sampled the memory use to see whether you are getting close to the limit?

I have a 600 byte struct stored using PROGMEM but when I memset it to 0

You can't write on flash memory at runtime. I suspect that that memset is actually trampling all over RAM, causing your crash, but as mentioned, you'll need to post your sketch for better help.