Skip to content

Commit

Permalink
Clarify return values and fix a minor issue (#271)
Browse files Browse the repository at this point in the history
Fix: Fl_Image_Reader::seek() would not clear the error flag when
reading from memory.
  • Loading branch information
Albrecht Schlosser committed Sep 25, 2021
1 parent bc0d18c commit 4075a14
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Fl_Image_Reader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ unsigned int Fl_Image_Reader::read_dword() {

// Move the current read position to a byte offset from the beginning
// of the file or the original start address in memory.
// This clears the error flag if the position is valid.
// This method clears the error flag if the position is valid.
// If reading from memory and (pStart + n) overflows, then the result is undefined.

void Fl_Image_Reader::seek(unsigned int n) {
pError = 0;
if (pIsFile) {
int ret = fseek(pFile, n , SEEK_SET);
if (ret < 0)
pError = 2; // read / position error
else
pError = 0;
return;
} else if (pIsData) {
if (pStart + n <= pEnd)
Expand All @@ -144,9 +145,12 @@ void Fl_Image_Reader::seek(unsigned int n) {
pError = 3;
}


// Get the current read position as a byte offset from the
// beginning of the file or the original start address in memory
// beginning of the file or the original start address in memory.
// This method does neither affect the error flag nor is it affected
// by the current error status. If reading from a file, this may
// return -1 or any error code from ftell().

long Fl_Image_Reader::tell() const {
if (pIsFile) {
return ftell(pFile);
Expand Down

0 comments on commit 4075a14

Please sign in to comment.