for loop error without Serial.print(i)

Hello,

I'm having an issue with my current project. I want to calculate a crc from a string and want to do it in a dedicated function.
However I'm having a strange issue, maybe due to the compiler : if a display the value of i in a Serial.print(), the code does as it should. If i remove it, the result seems to be random...

the function is the following:

int calculateCrc(char* strtocalc, int size_str){
  noInterrupts();
  int byte_sum = 0;
  for (int i=0; i< size_str; i++) {
    int s = strtocalc[i];
     byte_sum += s;
  //  Serial.print("i =");
  //  Serial.print(i);
  } 
  Serial.print("end of loop, result=");
  Serial.print(byte_sum);
  interrupts();
  return byte_sum;
}

the two commented line change the output : uncommenting them gives the expected result.
I taught some interrupt caused the issue, hence the stopinterrupts(), but it doesn't change anything.

I also tested to enter a manual string instead of a constructed one as an argument into the function : the problem doesn't append in this case... however when i print this constructed string before passing it as an argument: it is always the same one.

here is the function call with all the related code:

void sendToTecon()
{
   char temperature_setpoint_1[8];
   char temperature2_setpoint[8];
   char reg_start[8];
   sprintf(temperature2_setpoint,"%08x",(int)(tecon_setpoint_temperature2 * 10) );
   sprintf(temperature_setpoint_1,"%08x",(int)(tecon_setpoint_temperature1 * 10) );
   sprintf(reg_start,"%02x",(int)(tecon_reg_start) );

   char tecon_req[39];
    strcpy(tecon_req,"#0500C00");
    strcat(tecon_req,temperature_setpoint_1);
    strcat(tecon_req,temperature2_setpoint);
    strcat(tecon_req,"01");
    strcat(tecon_req,reg_start);
    strcat(tecon_req,"********");
  
    Serial.println(tecon_req);
  //  calculateCrc("#0500C00000000c8000000d2000000c80101********",36);   this works.....
    calculateCrc(tecon_req,36);
}

I'm really puzzled by this issue...

   char temperature_setpoint_1[8];
   char temperature2_setpoint[8];

   sprintf(temperature2_setpoint,"%08x",(int)(tecon_setpoint_temperature2 * 10) );
   sprintf(temperature_setpoint_1,"%08x",(int)(tecon_setpoint_temperature1 * 10) );

Both are missing a character.

Your arrays are one byte too short for 8 characters and a terminating null.