Skip to content

Fix buffer being overwritten by multiple twi_transmit calls #5014

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

Merged
merged 1 commit into from
Jun 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions hardware/arduino/avr/libraries/Wire/src/utility/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ uint8_t twi_transmit(const uint8_t* data, uint8_t length)
uint8_t i;

// ensure data will fit into buffer
if(TWI_BUFFER_LENGTH < length){
if(TWI_BUFFER_LENGTH < (twi_txBufferLength+length)){
return 1;
}

Expand All @@ -314,10 +314,10 @@ uint8_t twi_transmit(const uint8_t* data, uint8_t length)
}

// set length and copy data into tx buffer
twi_txBufferLength = length;
for(i = 0; i < length; ++i){
twi_txBuffer[i] = data[i];
twi_txBuffer[twi_txBufferLength+i] = data[i];
}
twi_txBufferLength += length;

return 0;
}
Expand Down