lib/file: Check if there are enough bytes left to read
parent
341b4c187e
commit
ec44ac9531
|
@ -61,10 +61,12 @@ ErrorOr<uint8_t> File::readByte(){
|
||||||
uint8_t* nextPointer = new uint8_t;
|
uint8_t* nextPointer = new uint8_t;
|
||||||
uint8_t nextByte;
|
uint8_t nextByte;
|
||||||
bool failure = false;
|
bool failure = false;
|
||||||
|
if (!this->size.isError && this->cursorPosition >= this->size.value) {
|
||||||
|
return ErrorOr<uint8_t>(true, ErrorCodes::OVERRUN);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
this->fileStream.seekg(this->cursorPosition);
|
this->fileStream.seekg(this->cursorPosition);
|
||||||
|
|
||||||
//FIXME: check that a byte is available for read
|
|
||||||
this->fileStream.read(reinterpret_cast<char*>(nextPointer), 1);
|
this->fileStream.read(reinterpret_cast<char*>(nextPointer), 1);
|
||||||
nextByte = *nextPointer;
|
nextByte = *nextPointer;
|
||||||
|
|
||||||
|
@ -81,6 +83,9 @@ ErrorOr<std::vector<uint8_t>> File::read(uint64_t bytes){
|
||||||
uint8_t* buffer = new uint8_t[bytes];
|
uint8_t* buffer = new uint8_t[bytes];
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
bool failure = false;
|
bool failure = false;
|
||||||
|
if (!this->size.isError && this->cursorPosition >= this->size.value+bytes) {
|
||||||
|
return ErrorOr<std::vector<uint8_t>>(true, ErrorCodes::OVERRUN);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
this->fileStream.seekg(this->cursorPosition);
|
this->fileStream.seekg(this->cursorPosition);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue