From 2fed7a894a14d82a0e930c82991f58ef7bc60fba Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Wed, 11 Dec 2024 18:40:32 +0100 Subject: [PATCH] Add assertion --- cpp/controllers/abstract_controller.cpp | 6 ++++++ cpp/controllers/controller.cpp | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cpp/controllers/abstract_controller.cpp b/cpp/controllers/abstract_controller.cpp index 9be8432f..b6bae552 100644 --- a/cpp/controllers/abstract_controller.cpp +++ b/cpp/controllers/abstract_controller.cpp @@ -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; } diff --git a/cpp/controllers/controller.cpp b/cpp/controllers/controller.cpp index 5cece8f8..e1447696 100644 --- a/cpp/controllers/controller.cpp +++ b/cpp/controllers/controller.cpp @@ -357,7 +357,7 @@ void Controller::Send() UpdateTransferSize(); - if (GetRemainingLength() > 0) { + if (GetRemainingLength()) { if (IsDataIn()) { TransferToHost(); } @@ -444,7 +444,7 @@ void Controller::Receive() break; } - if (GetRemainingLength() > 0) { + if (GetRemainingLength()) { assert(GetCurrentLength()); assert(!GetOffset()); return; @@ -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(); }