Author Topic: Bug in RFduinoGZLLClass::sendToHost and RFduinoGZLLClass::sendToDevice ?  (Read 1827 times)

jfp

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Hi,

looking at the code in RFduinoGZLL.cpp I suspect a small bug in the 2 routines RFduinoGZLLClass::sendToHost and RFduinoGZLLClass::sendToDevice

If I have correctly understood, it is possible to exchange message up to 32 bytes.

But both routines contains the following sequence:
Code: [Select]
char buf[32];
 data.toCharArray(buf, sizeof(buf));
But the routine String::toCharArray which just call String::getBytes is (extract)
Code: [Select]
unsigned int n = bufsize - 1;
if (n > len - index) n = len - index;
strncpy((char *)buf, buffer + index, n);
buf[n] = 0;

The buffer is always null terminated and only bufsize - 1 are copied.

So the variable buf, declared in sendToHost and sendtoDevice, should be 33 characters long and not 32.

JF

jfp

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Hi mkay,

no, an array declaration in C use the length of the array not the last indice.

So char foo[32] declare a 32 char array not a 33 char array... valid indices are in range 0..31 not 0..32

JF
« Last Edit: March 18, 2014, 04:04:25 AM by jfp »

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Hi jpf, my mistake yes you are correct... I was not paying close attention:) We'll take a look at this.