← Back to team overview

kicad-developers team mailing list archive

[PATCH 01/11] Avoid comparing filepos with integers

 

The filepos type is not necessarily an integer type, because it also needs
to save the multibyte character state in case we're reading from a stream
with shift states.

The convention of using -1 as a special value is from Unix ftell(), and not
portable. Instead, the stream's failbit needs to be examined after the call
to tellg().
---
 utils/idftools/idf_helpers.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/utils/idftools/idf_helpers.cpp b/utils/idftools/idf_helpers.cpp
index 798ea0c..f0052f5 100644
--- a/utils/idftools/idf_helpers.cpp
+++ b/utils/idftools/idf_helpers.cpp
@@ -34,12 +34,12 @@ using namespace IDF3;
 // fetch a line from the given input file and trim the ends
 bool IDF3::FetchIDFLine( std::ifstream& aModel, std::string& aLine, bool& isComment, std::streampos& aFilePos )
 {
+    if( aModel.fail() )
+        return false;
+
     aLine = "";
     aFilePos = aModel.tellg();
 
-    if( aFilePos == -1 )
-        return false;
-
     std::getline( aModel, aLine );
 
     isComment = false;

Follow ups

References