← Back to team overview

kicad-developers team mailing list archive

[PATCH v2] 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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/idftools/idf_helpers.cpp b/utils/idftools/idf_helpers.cpp
index 798ea0c..a9ab11e 100644
--- a/utils/idftools/idf_helpers.cpp
+++ b/utils/idftools/idf_helpers.cpp
@@ -37,7 +37,7 @@ bool IDF3::FetchIDFLine( std::ifstream& aModel, std::string& aLine, bool& isComm
     aLine = "";
     aFilePos = aModel.tellg();
 
-    if( aFilePos == -1 )
+    if( aModel.fail() )
         return false;
 
     std::getline( aModel, aLine );

References