FLTK logo

[master] 4075a14 - Clarify return values and fix a minor issue (#271)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 4075a14 - Clarify return values and fix a minor issue (#271) "Albrecht Schlosser" Sep 25, 2021  
 
commit 4075a14715ef1935dd82f49e4d84eea218087dfd
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Sat Sep 25 20:19:51 2021 +0200
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Sat Sep 25 20:19:51 2021 +0200

    Clarify return values and fix a minor issue (#271)
    
    Fix: Fl_Image_Reader::seek() would not clear the error flag when
    reading from memory.

 src/Fl_Image_Reader.cxx | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git src/Fl_Image_Reader.cxx src/Fl_Image_Reader.cxx
index 63cd145..b9a2425 100644
--- src/Fl_Image_Reader.cxx
+++ src/Fl_Image_Reader.cxx
@@ -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)
@@ -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);
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.