     serial_buffer[num_read] = 0;// terminate the string
     if (serial_buffer[0] || current_buffer[0]) {
       if (serial_buffer[0])
-        strcat(current_buffer, serial_buffer);
+		  if (strlen(serial_buffer) + strlen(current_buffer) < MAX_BUFFER_LENGTH) // concat only if it fits
+			strcat(current_buffer, serial_buffer);
 
 #ifdef DEBUG
       Serial.write("initial buffer is=");

//Main loop
void loop()
{
  char serial_out[100];

  // check to see if there are new results from ultrasonic sensor
  ultrasonic_sensors_controller.update_results(serial_out);


char firmware_version[20];// year.month.day.build number

#define MAX_BUFFER_LENGTH 100

char current_buffer[MAX_BUFFER_LENGTH];

//#define DEBUG
//#define PRINT_HELP
