Browse Source

X: fix some review findings.

Kim Kulling 7 năm trước cách đây
mục cha
commit
ff556027ef
1 tập tin đã thay đổi với 31 bổ sung30 xóa
  1. 31 30
      code/XFileParser.cpp

+ 31 - 30
code/XFileParser.cpp

@@ -466,12 +466,11 @@ void XFileParser::ParseDataObjectMesh( Mesh* pMesh)
     // read position faces
     // read position faces
     unsigned int numPosFaces = ReadInt();
     unsigned int numPosFaces = ReadInt();
     pMesh->mPosFaces.resize( numPosFaces);
     pMesh->mPosFaces.resize( numPosFaces);
-    for( unsigned int a = 0; a < numPosFaces; a++)
-    {
+    for( unsigned int a = 0; a < numPosFaces; ++a) {
         // read indices
         // read indices
         unsigned int numIndices = ReadInt();
         unsigned int numIndices = ReadInt();
         Face& face = pMesh->mPosFaces[a];
         Face& face = pMesh->mPosFaces[a];
-        for (unsigned int b = 0; b < numIndices; b++) {
+        for (unsigned int b = 0; b < numIndices; ++b) {
             face.mIndices.push_back( ReadInt() );
             face.mIndices.push_back( ReadInt() );
         }
         }
         TestForSeparator();
         TestForSeparator();
@@ -479,11 +478,10 @@ void XFileParser::ParseDataObjectMesh( Mesh* pMesh)
 
 
     // here, other data objects may follow
     // here, other data objects may follow
     bool running = true;
     bool running = true;
-    while ( running )
-    {
+    while ( running ) {
         std::string objectName = GetNextToken();
         std::string objectName = GetNextToken();
 
 
-        if( objectName.size() == 0)
+        if( objectName.empty() )
             ThrowException( "Unexpected end of file while parsing mesh structure");
             ThrowException( "Unexpected end of file while parsing mesh structure");
         else
         else
         if( objectName == "}")
         if( objectName == "}")
@@ -518,8 +516,10 @@ void XFileParser::ParseDataObjectMesh( Mesh* pMesh)
 }
 }
 
 
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
-void XFileParser::ParseDataObjectSkinWeights( Mesh *pMesh)
-{
+void XFileParser::ParseDataObjectSkinWeights( Mesh *pMesh) {
+    if ( nullptr == pMesh ) {
+        return;
+    }
     readHeadOfDataObject();
     readHeadOfDataObject();
 
 
     std::string transformNodeName;
     std::string transformNodeName;
@@ -1053,39 +1053,40 @@ void XFileParser::readHeadOfDataObject( std::string* poName)
 }
 }
 
 
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
-std::string XFileParser::GetNextToken()
-{
+std::string XFileParser::GetNextToken() {
     std::string s;
     std::string s;
 
 
     // process binary-formatted file
     // process binary-formatted file
-    if( mIsBinaryFormat)
-    {
+    if( mIsBinaryFormat) {
         // in binary mode it will only return NAME and STRING token
         // in binary mode it will only return NAME and STRING token
         // and (correctly) skip over other tokens.
         // and (correctly) skip over other tokens.
-
-        if( mEnd - mP < 2) return s;
+        if ( mEnd - mP < 2 ) {
+            return s;
+        }
         unsigned int tok = ReadBinWord();
         unsigned int tok = ReadBinWord();
         unsigned int len;
         unsigned int len;
 
 
         // standalone tokens
         // standalone tokens
-        switch( tok)
-        {
+        switch( tok ) {
             case 1: {
             case 1: {
-                    // name token
-                    if ( mEnd - mP < 4 ) return s;
-                    len = ReadBinDWord();
-                    const int bounds( mEnd - mP );
-                    const int iLen( len );
-                    if ( iLen < 0 ) {
-                        return s;
-                    }
-                    if ( bounds < iLen ) {
-                        return s;
-                    }
-                    s = std::string( mP, len );
-                    mP += len;
+                // name token
+                if ( mEnd - mP < 4 ) {
+                    return s;
                 }
                 }
-                return s;
+                len = ReadBinDWord();
+                const int bounds( mEnd - mP );
+                const int iLen( len );
+                if ( iLen < 0 ) {
+                    return s;
+                }
+                if ( bounds < iLen ) {
+                    return s;
+                }
+                s = std::string( mP, len );
+                mP += len;
+            }
+            return s;
+
             case 2:
             case 2:
                 // string token
                 // string token
                 if( mEnd - mP < 4) return s;
                 if( mEnd - mP < 4) return s;