writting to buffer from serial input Can some one explain this behaviour please, i have the following code

  byte buffer[512];
  byte block;
  byte len;

  Serial.setTimeout(60000L) ;     // wait until 20 seconds for input from serial
  // Ask personal data: Family name
  Serial.println(F("Type text followed by #"));
  len = Serial.readBytesUntil('#', (char *) buffer, 500) ; // read from serial
  Serial.print(len);
  for (byte i = len; i &lt; 250; i++) buffer[i] = '#';     // pad with #
  Serial.print(len);


This works but if i change the "for" line to any thing higer then 250 it stops working and there is a "buffer out of memory condition) 

My question is why can't the for loop say the below as the buffer size is 512? 

for (byte i = len; i &lt; 512; i++) buffer[i] = '#'; 


Am i right in thinking it has something to do with  (Char *), i did copy this code from the example ardunio code and was jsut trying to incress the lenth of input it accpeted.
A byte can only contain values from 0 to 255 (including). 

So my guess it works for values until 255.

You should use a different type, e.g. unsigned int or unsigned short.

for (unsigned short i = len; i &lt; 250; i++) buffer[i] = '#';     // pad with #


Also, I advise to use a constant or define for the buffer size, now you have 3 values (512, 500 and 250 in the loop, I assume they should be based on the same value).

About the char*: Looking at StreamReadBytesUntil, it seems that the parameter wants a char* instead of a byte* (which is more or less the same), but it's better to cast to show the parameter is of type char* since that is high likely the exact type (but the official Arduino documentation does not show the parameter types sadly).