SDFile - fix errorneous offset computation
... my fault, I was originally too optimistic about the overflow Fixes #3077 PFW-1233
This commit is contained in:
parent
a251dcc14e
commit
cdcc06f376
1 changed files with 8 additions and 5 deletions
|
@ -178,14 +178,17 @@ eof_or_fail:
|
|||
}
|
||||
|
||||
bool SdFile::gfEnsureBlock(){
|
||||
if ( vol_->cacheRawBlock(gfBlock, SdVolume::CACHE_FOR_READ)){
|
||||
// this comparison is heavy-weight, especially when there is another one inside cacheRawBlock
|
||||
// but it is necessary to avoid computing of terminateOfs if not needed
|
||||
if( gfBlock != vol_->cacheBlockNumber_ ){
|
||||
if ( ! vol_->cacheRawBlock(gfBlock, SdVolume::CACHE_FOR_READ)){
|
||||
return false;
|
||||
}
|
||||
// terminate with a '\n'
|
||||
const uint16_t terminateOfs = fileSize_ - gfOffset;
|
||||
const uint32_t terminateOfs = fileSize_ - gfOffset;
|
||||
vol_->cache()->data[ terminateOfs < 512 ? terminateOfs : 512 ] = '\n';
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SdFile::gfComputeNextFileBlock() {
|
||||
|
|
Loading…
Reference in a new issue