This is a bug report concerning compiler errors when manipulating 16-bit values that may result in a 32-bit result.
I have code that converts a Bluetooth time and date representation (Date Time characteristic UUID 0x2A08) into seconds since 1 January 2000, for subsequent time/date arithmetic. I am re-using code that works on other platforms, and which finishes with this:
*seconds = (i * 86400) + (buf * 3600) + (buf * 60) + buf + 1;
where i is the number of days since 1/1/2000 and buf, buf and buf are hours, minutes and seconds from the BLE Date Time characteristic. seconds is a uint32 and buf is unit8.
The code works for hours up till 6pm but fails at 7pm. It turns out that 6pm is 18*3600=64,800 (<2^16) but 7pm is 19*3600=68,400 (>2^16). It is apparent that the compiler fails to perform arithmetic correctly when (buf * 3600) exceeds 16 bits.
The following refactored code works correctly:
*seconds = (i * 86400);
*seconds += ((uint32) buf) * 3600;
*seconds += (buf * 60) + buf + 1;
Is CSR aware of this bug? Is CSR concerned about this bug? What other compiler bugs exist? Are they documented? Does anyone from CSR monitor this forum? I have not received any comments on my earlier CSR1010 compiler bug post: https://developer.qualcomm.com/forum/qdn-forums/hardware/bluetooth-conne...