Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SFE-Brudnerd opened this issue Mar 12, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@SFE-Brudnerd
Copy link
Member

SFE-Brudnerd commented Mar 12, 2025

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;
}

@SFE-Brudnerd SFE-Brudnerd added the bug Something isn't working label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant