Skip to content

Commit

Permalink
Add assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 11, 2024
1 parent 19d8863 commit 2fed7a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cpp/controllers/abstract_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ void AbstractController::SetTransferSize(int length, int size)
void AbstractController::UpdateTransferSize()
{
remaining_length -= chunk_size;

assert(remaining_length >= 0);
if (remaining_length < 0) {
remaining_length = 0;
}

if (remaining_length < chunk_size) {
chunk_size = remaining_length;
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/controllers/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void Controller::Send()

UpdateTransferSize();

if (GetRemainingLength() > 0) {
if (GetRemainingLength()) {
if (IsDataIn()) {
TransferToHost();
}
Expand Down Expand Up @@ -444,7 +444,7 @@ void Controller::Receive()
break;
}

if (GetRemainingLength() > 0) {
if (GetRemainingLength()) {
assert(GetCurrentLength());
assert(!GetOffset());
return;
Expand Down Expand Up @@ -493,7 +493,7 @@ bool Controller::TransferFromHost(int length)
}
else {
length = device->WriteData(GetCdb(), GetBuffer(), -1, length);
if (GetRemainingLength() > 0) {
if (GetRemainingLength()) {
SetCurrentLength(length);
ResetOffset();
}
Expand Down

0 comments on commit 2fed7a8

Please sign in to comment.