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 @@ -876,23 +876,25 @@ void USBMSD::memoryRead(void)
876
876
877
877
n = (_length > MAX_PACKET) ? MAX_PACKET : _length;
878
878
879
- if (( _addr + n) > _memory_size) {
880
- n = _memory_size - _addr;
879
+ if (_addr > ( _memory_size - n) ) {
880
+ n = _addr < _memory_size ? _memory_size - _addr : 0 ;
881
881
_stage = ERROR;
882
882
}
883
883
884
- // we read an entire block
885
- if (!(_addr % _block_size)) {
886
- disk_read (_page, _addr / _block_size, 1 );
887
- }
884
+ if (n > 0 ) {
885
+ // we read an entire block
886
+ if (!(_addr % _block_size)) {
887
+ disk_read (_page, _addr / _block_size, 1 );
888
+ }
888
889
889
- // write data which are in RAM
890
- _write_next (&_page[_addr % _block_size], MAX_PACKET);
890
+ // write data which are in RAM
891
+ _write_next (&_page[_addr % _block_size], MAX_PACKET);
891
892
892
- _addr += n;
893
- _length -= n;
893
+ _addr += n;
894
+ _length -= n;
894
895
895
- _csw.DataResidue -= n;
896
+ _csw.DataResidue -= n;
897
+ }
896
898
897
899
if (!_length || (_stage != PROCESS_CBW)) {
898
900
_csw.Status = (_stage == PROCESS_CBW) ? CSW_PASSED : CSW_FAILED;
You can’t perform that action at this time.
0 commit comments