Bug or misunderstood I don't know

Hello
I’m stuck on a problem either I don’t understand or I discovered a bug, I’ll explain
here is the code in question


uint8_t send_2C_clear[7] = {0xB8, 0x13, 0xF7, 0x03, 0x2C, 0xF0, 0x04}; //
K_Line.envoie(send_2C_clear, 7);

bool k_Line::envoie(uint8_t data_send[],uint8_t len)
{
  if (Envoie == true)
  { 
    Serial.println("ENVOIEEE");
    data_len=0;
    data_len = len;
   
     Serial.print("len = ");
     Serial.println(len);

    data_send[len] = checksum(len, data_send); // demande de checksum Y = resultat du checksum
    
    Serial.print("checksum = ");
    Serial.println(data_send[len],HEX);
    Serial.print("envoi = ");
    clear();
    for (int i = 0; i < len + 1; i++)
    {
      Serial2.write(data_send[i]); // envois de la demande ECU
      Serial.print(data_send[i],HEX);
      Serial.print(",");
    }
    
    Serial.println("");
    Envoie = false;
  }
  return Envoie;
}

uint8_t k_Line::checksum(uint8_t length, uint8_t data[])
{
  uint8_t tchecksum;
 
  for (int i = 0; i < length; i++)
  {
    tchecksum ^= data[i];
  }
  return tchecksum;
}

void k_Line::clear()
{
  while(Serial2.available()>0) { char inChar = Serial2.read();}
}

Serial.print =
ENVOIEEE
len = 7
checksum = 87
envoi = A0,13,F7,3,2C,F0,4,87

My question is where does this A0 come from?
This only appears when I do the clear() function
if I remove it I have send = B8,13,F7,3,2C,F0,4,87
impossible to understand why

It would be very helpful if you provide a minimal but full working example that makes the error reproducible. English function and variable names are also welcome in order to understand the meaning of them.

A platformio.ini would also be helpful to understand on which platform / framework the code should run.

As far as I can see, you are trying to add an eighth byte to an array that is 7 bytes long. (out of bound)

Accessing an array out of bound is undefined behavior.
So anything can happen…