Skip to content

Arduino I2C implementation doesn't check for device register validity. #44

Closed
@SFE-Brudnerd

Description

@SFE-Brudnerd

There is no checking done to ensure that devReg is not nullptr. IMO this could be accomplished by adding a check above the write on line 168 like so.

if (devReg != nullptr && regLength > 0)
    _i2cPort->write(devReg, regLength);

sfTkError_t sfTkArdI2C::readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes,
size_t &readBytes)
{
// got port
if (!_i2cPort)
return ksfTkErrBusNotInit;
// Buffer valid?
if (!data)
return ksfTkErrBusNullBuffer;
readBytes = 0;
uint16_t nOrig = numBytes; // original number of bytes.
uint8_t nChunk;
uint16_t nReturned;
uint16_t i; // counter in loop
bool bFirstInter = true; // Flag for first iteration - used to send devRegister
while (numBytes > 0)
{
if (bFirstInter)
{
_i2cPort->beginTransmission(address());
_i2cPort->write(devReg, regLength);
if (_i2cPort->endTransmission(stop()) != 0)
return ksfTkErrFail; // error with the end transmission
bFirstInter = false;
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions