Skip to content

Commit

Permalink
Check current position against size in FileStream::write() and `F…
Browse files Browse the repository at this point in the history
…ileStream::seek()`

Fixes problem where `available()` reports negative value
  • Loading branch information
mikee47 committed Feb 8, 2019
1 parent 8dc96a5 commit d3bde16
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Sming/SmingCore/Data/Stream/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@ size_t FileStream::write(const uint8_t* buffer, size_t size)
return 0;
}

int pos = fileSeek(handle, 0, eSO_FileEnd);
if(!check(pos)) {
int writePos = fileSeek(handle, 0, eSO_FileEnd);
if(!check(writePos)) {
return 0;
}

this->pos = size_t(pos);
pos = size_t(writePos);

int written = fileWrite(handle, buffer, size);
if(check(written)) {
this->pos += size_t(written);
pos += size_t(written);
if(pos > this->size) {
this->size = pos;
}
}

return written;
Expand All @@ -98,7 +101,10 @@ bool FileStream::seek(int len)
return false;
}

pos = newpos;
pos = size_t(newpos);
if(pos > size) {
size = pos;
}

return true;
}
Expand Down

0 comments on commit d3bde16

Please sign in to comment.