File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -869,23 +869,25 @@ void USBMSD::memoryRead(void)
869
869
870
870
n = (_length > MAX_PACKET) ? MAX_PACKET : _length;
871
871
872
- if (( _addr + n) > _memory_size) {
873
- n = _memory_size - _addr;
872
+ if (_addr > ( _memory_size - n) ) {
873
+ n = _addr < _memory_size ? _memory_size - _addr : 0 ;
874
874
_stage = ERROR;
875
875
}
876
876
877
- // we read an entire block
878
- if (!(_addr % _block_size)) {
879
- disk_read (_page, _addr / _block_size, 1 );
880
- }
877
+ if (n > 0 ) {
878
+ // we read an entire block
879
+ if (!(_addr % _block_size)) {
880
+ disk_read (_page, _addr / _block_size, 1 );
881
+ }
881
882
882
- // write data which are in RAM
883
- _write_next (&_page[_addr % _block_size], MAX_PACKET);
883
+ // write data which are in RAM
884
+ _write_next (&_page[_addr % _block_size], MAX_PACKET);
884
885
885
- _addr += n;
886
- _length -= n;
886
+ _addr += n;
887
+ _length -= n;
887
888
888
- _csw.DataResidue -= n;
889
+ _csw.DataResidue -= n;
890
+ }
889
891
890
892
if (!_length || (_stage != PROCESS_CBW)) {
891
893
_csw.Status = (_stage == PROCESS_CBW) ? CSW_PASSED : CSW_FAILED;
You can’t perform that action at this time.
0 commit comments