]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/imagtga.cpp
Rewind the input stream after failing to load image from it.
[wxWidgets.git] / src / common / imagtga.cpp
index fc7373822bb0090ac06b3751027ebeb3d70538d2..62080d22c1f5490cb0d852ce9f6bf3e35f08ebcb 100644 (file)
@@ -211,7 +211,8 @@ int ReadTGA(wxImage* image, wxInputStream& stream)
     }
 
     // Seek from the offset we got from the TGA header.
-    stream.SeekI(offset, wxFromStart);
+    if (stream.SeekI(offset, wxFromStart) == wxInvalidOffset)
+        return wxTGA_INVFORMAT;
 
     // Load a palette if we have one.
     if (colorType == wxTGA_MAPPED)
@@ -668,7 +669,9 @@ bool wxTGAHandler::LoadFile(wxImage* image,
     if ( !CanRead(stream) )
     {
         if ( verbose )
+        {
             wxLogError(wxT("TGA: this is not a TGA file."));
+        }
 
         return false;
     }
@@ -740,7 +743,7 @@ bool wxTGAHandler::DoCanRead(wxInputStream& stream)
 {
     // read the fixed-size TGA headers
     unsigned char hdr[HDR_SIZE];
-    stream.Read(hdr, HDR_SIZE);
+    stream.Read(hdr, HDR_SIZE);     // it's ok to modify the stream position here
 
     // Check wether we can read the file or not.