← Back to team overview

kicad-developers team mailing list archive

PATCH: change test for invalid numeric strings in VRML files

 

The attached patch changes a test for invalid numeric strings
in VRML1,2 and X3D files. The long-winded and convoluted
tests similar in form to:

    istr >> aSFFloat;
    tmp.clear();
    istr >> tmp;

    if( !tmp.empty() )

Are replaced with a more obvious and shorter test:

    istr >> aSFFloat;
    if( istr.fail() || !istr.eof() )

- Cirilo
From fd28ef5431dc95ce330d8eeb59cdc276cf4f2a19 Mon Sep 17 00:00:00 2001
From: Cirilo Bernardo <cirilo.bernardo@xxxxxxxxx>
Date: Mon, 26 Sep 2016 20:52:31 +1000
Subject: [PATCH] Changed test for invalid numeric strings in VRML files
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.9.3"

This is a multi-part message in MIME format.
--------------2.9.3
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit

---
 plugins/3d/vrml/wrlproc.cpp | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)


--------------2.9.3
Content-Type: text/x-patch; name="0001-Changed-test-for-invalid-numeric-strings-in-VRML-fil.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-Changed-test-for-invalid-numeric-strings-in-VRML-fil.patch"

diff --git a/plugins/3d/vrml/wrlproc.cpp b/plugins/3d/vrml/wrlproc.cpp
index bbabce8..e12a19f 100644
--- a/plugins/3d/vrml/wrlproc.cpp
+++ b/plugins/3d/vrml/wrlproc.cpp
@@ -828,12 +828,9 @@ bool WRLPROC::ReadSFFloat( float& aSFFloat )
 
     std::istringstream istr;
     istr.str( tmp );
-
     istr >> aSFFloat;
-    tmp.clear();
-    istr >> tmp;
 
-    if( !tmp.empty() )
+    if( istr.fail() || !istr.eof() )
     {
         std::ostringstream ostr;
         ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
@@ -901,12 +898,9 @@ bool WRLPROC::ReadSFInt( int& aSFInt32 )
 
     std::istringstream istr;
     istr.str( tmp );
-
     istr >> aSFInt32;
-    tmp.clear();
-    istr >> tmp;
 
-    if( !tmp.empty() )
+    if( istr.fail() || !istr.eof() )
     {
         std::ostringstream ostr;
         ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
@@ -971,12 +965,9 @@ bool WRLPROC::ReadSFRotation( WRLROTATION& aSFRotation )
 
         std::istringstream istr;
         istr.str( tmp );
-
         istr >> trot[i];
-        tmp.clear();
-        istr >> tmp;
 
-        if( !tmp.empty() )
+        if( istr.fail() || !istr.eof() )
         {
             std::ostringstream ostr;
             ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
@@ -1047,12 +1038,9 @@ bool WRLPROC::ReadSFVec2f( WRLVEC2F& aSFVec2f )
 
         std::istringstream istr;
         istr.str( tmp );
-
         istr >> tcol[i];
-        tmp.clear();
-        istr >> tmp;
 
-        if( !tmp.empty() )
+        if( istr.fail() || !istr.eof() )
         {
             std::ostringstream ostr;
             ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
@@ -1129,12 +1117,9 @@ bool WRLPROC::ReadSFVec3f( WRLVEC3F& aSFVec3f )
 
         std::istringstream istr;
         istr.str( tmp );
-
         istr >> tcol[i];
-        tmp.clear();
-        istr >> tmp;
 
-        if( !tmp.empty() )
+        if( istr.fail() || !istr.eof() )
         {
             std::ostringstream ostr;
             ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";

--------------2.9.3--



Follow ups