bl_iot_sdk icon indicating copy to clipboard operation
bl_iot_sdk copied to clipboard

Bug in static void i2c_transferbytes(i2c_msg_t *pstmsg)?

Open Kongduino opened this issue 3 years ago • 6 comments

In static void i2c_transferbytes(i2c_msg_t *pstmsg) there are 2 if conditions that have a single =.

if ((pstmsg->direct == I2C_M_WRITE) && (pstmsg->event = EV_I2C_TXF_INT)) {

and

    } else if ((pstmsg->direct == I2C_M_READ) && (pstmsg->event = EV_I2C_RXF_INT)){

This looks suspiciously like they should be == equality tests.

Kongduino avatar Jan 26 '21 11:01 Kongduino

The Assignment in the Condition looks suspicious because pstmsg->event has already been set by the calling function i2c_interrupt_entry ... Yet pstmsg->event isn't used after i2c_transferbytes returns to i2c_interrupt_entry

lupyuen avatar Jan 26 '21 13:01 lupyuen

Hi

This may be an issue. We will check this code, thanks for your information.

shchen-Lab avatar Jan 27 '21 05:01 shchen-Lab

@lupyuen @Kongduino This issue will be fixed, thanks!

shchen-Lab avatar Jan 27 '21 05:01 shchen-Lab

Awesome thank you :-)

lupyuen avatar Jan 27 '21 05:01 lupyuen

好的👌!

Kongduino avatar Jan 27 '21 09:01 Kongduino

@shchen-Lab , has a fix for this been committed? If so, please close this. Bonus points for referencing the git hash of the submit that fix it, but omitting that is OK. Leaving this dangling for two years isn't great. Thanx.

To prevent this kind of thing in the future, please consider integrating one of the many GCC/Clang flags to detect (if foo = bar) vs if ((foo == bar)). They're not totally satisfying, but automation in a large code base can really help.

robertlipe avatar Oct 14 '23 08:10 robertlipe