Quellcode durchsuchen

Fixed cppcheck warnings

PKEuS vor 13 Jahren
Ursprung
Commit
c28ba3aeab
3 geänderte Dateien mit 13 neuen und 14 gelöschten Zeilen
  1. 3 4
      tinyxml2.cpp
  2. 7 7
      tinyxml2.h
  3. 3 3
      xmltest.cpp

+ 3 - 4
tinyxml2.cpp

@@ -190,8 +190,6 @@ const char* StrPair::GetStr()
 					*q++ = LF;
 					*q++ = LF;
 				}
 				}
 				else if ( (flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
 				else if ( (flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
-					int i=0;
-
 					// Entities handled by tinyXML2:
 					// Entities handled by tinyXML2:
 					// - special entities in the entity table [in/out]
 					// - special entities in the entity table [in/out]
 					// - numeric character reference [in]
 					// - numeric character reference [in]
@@ -207,7 +205,8 @@ const char* StrPair::GetStr()
 						TIXMLASSERT( q <= p );
 						TIXMLASSERT( q <= p );
 					}
 					}
 					else {
 					else {
-						for( i=0; i<NUM_ENTITIES; ++i ) {
+						int i=0;
+						for(; i<NUM_ENTITIES; ++i ) {
 							if (    strncmp( p+1, entities[i].pattern, entities[i].length ) == 0
 							if (    strncmp( p+1, entities[i].pattern, entities[i].length ) == 0
 								 && *(p+entities[i].length+1) == ';' ) 
 								 && *(p+entities[i].length+1) == ';' ) 
 							{
 							{
@@ -768,7 +767,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
 		// We read the end tag. Return it to the parent.
 		// We read the end tag. Return it to the parent.
 		if ( node->ToElement() && node->ToElement()->ClosingType() == XMLElement::CLOSING ) {
 		if ( node->ToElement() && node->ToElement()->ClosingType() == XMLElement::CLOSING ) {
 			if ( parentEnd ) {
 			if ( parentEnd ) {
-				*parentEnd = ((XMLElement*)node)->value;
+				*parentEnd = static_cast<XMLElement*>(node)->value;
 			}
 			}
 			DELETE_NODE( node );
 			DELETE_NODE( node );
 			return p;
 			return p;

+ 7 - 7
tinyxml2.h

@@ -587,7 +587,7 @@ protected:
 	XMLNode( XMLDocument* );
 	XMLNode( XMLDocument* );
 	virtual ~XMLNode();
 	virtual ~XMLNode();
 	XMLNode( const XMLNode& );	// not supported
 	XMLNode( const XMLNode& );	// not supported
-	void operator=( const XMLNode& );	// not supported
+	XMLNode& operator=( const XMLNode& );	// not supported
 	
 	
 	XMLDocument*	document;
 	XMLDocument*	document;
 	XMLNode*		parent;
 	XMLNode*		parent;
@@ -641,7 +641,7 @@ protected:
 	XMLText( XMLDocument* doc )	: XMLNode( doc ), isCData( false )	{}
 	XMLText( XMLDocument* doc )	: XMLNode( doc ), isCData( false )	{}
 	virtual ~XMLText()												{}
 	virtual ~XMLText()												{}
 	XMLText( const XMLText& );	// not supported
 	XMLText( const XMLText& );	// not supported
-	void operator=( const XMLText& );	// not supported
+	XMLText& operator=( const XMLText& );	// not supported
 
 
 private:
 private:
 	bool isCData;
 	bool isCData;
@@ -666,7 +666,7 @@ protected:
 	XMLComment( XMLDocument* doc );
 	XMLComment( XMLDocument* doc );
 	virtual ~XMLComment();
 	virtual ~XMLComment();
 	XMLComment( const XMLComment& );	// not supported
 	XMLComment( const XMLComment& );	// not supported
-	void operator=( const XMLComment& );	// not supported
+	XMLComment& operator=( const XMLComment& );	// not supported
 
 
 private:
 private:
 };
 };
@@ -700,7 +700,7 @@ protected:
 	XMLDeclaration( XMLDocument* doc );
 	XMLDeclaration( XMLDocument* doc );
 	virtual ~XMLDeclaration();
 	virtual ~XMLDeclaration();
 	XMLDeclaration( const XMLDeclaration& );	// not supported
 	XMLDeclaration( const XMLDeclaration& );	// not supported
-	void operator=( const XMLDeclaration& );	// not supported
+	XMLDeclaration& operator=( const XMLDeclaration& );	// not supported
 };
 };
 
 
 
 
@@ -728,7 +728,7 @@ protected:
 	XMLUnknown( XMLDocument* doc );
 	XMLUnknown( XMLDocument* doc );
 	virtual ~XMLUnknown();
 	virtual ~XMLUnknown();
 	XMLUnknown( const XMLUnknown& );	// not supported
 	XMLUnknown( const XMLUnknown& );	// not supported
-	void operator=( const XMLUnknown& );	// not supported
+	XMLUnknown& operator=( const XMLUnknown& );	// not supported
 };
 };
 
 
 
 
@@ -1265,7 +1265,7 @@ public:
 	/// Copy constructor
 	/// Copy constructor
 	XMLHandle( const XMLHandle& ref )										{ node = ref.node; }
 	XMLHandle( const XMLHandle& ref )										{ node = ref.node; }
 	/// Assignment
 	/// Assignment
-	XMLHandle operator=( const XMLHandle& ref )								{ node = ref.node; return *this; }
+	XMLHandle& operator=( const XMLHandle& ref )							{ node = ref.node; return *this; }
 
 
 	/// Get the first child of this handle.
 	/// Get the first child of this handle.
 	XMLHandle FirstChild() 													{ return XMLHandle( node ? node->FirstChild() : 0 ); }
 	XMLHandle FirstChild() 													{ return XMLHandle( node ? node->FirstChild() : 0 ); }
@@ -1311,7 +1311,7 @@ public:
 	XMLConstHandle( const XMLNode& _node )											{ node = &_node; }
 	XMLConstHandle( const XMLNode& _node )											{ node = &_node; }
 	XMLConstHandle( const XMLConstHandle& ref )										{ node = ref.node; }
 	XMLConstHandle( const XMLConstHandle& ref )										{ node = ref.node; }
 
 
-	XMLConstHandle operator=( const XMLConstHandle& ref )							{ node = ref.node; return *this; }
+	XMLConstHandle& operator=( const XMLConstHandle& ref )							{ node = ref.node; return *this; }
 
 
 	const XMLConstHandle FirstChild() const											{ return XMLConstHandle( node ? node->FirstChild() : 0 ); }
 	const XMLConstHandle FirstChild() const											{ return XMLConstHandle( node ? node->FirstChild() : 0 ); }
 	const XMLConstHandle FirstChildElement( const char* value=0 ) const				{ return XMLConstHandle( node ? node->FirstChildElement( value ) : 0 ); }
 	const XMLConstHandle FirstChildElement( const char* value=0 ) const				{ return XMLConstHandle( node ? node->FirstChildElement( value ) : 0 ); }

+ 3 - 3
xmltest.cpp

@@ -411,8 +411,6 @@ int main( int /*argc*/, const char ** /*argv*/ )
 		doc.SaveFile( "resources/utf8testout.xml" );
 		doc.SaveFile( "resources/utf8testout.xml" );
 
 
 		// Check the round trip.
 		// Check the round trip.
-		char savedBuf[256];
-		char verifyBuf[256];
 		int okay = 0;
 		int okay = 0;
 
 
 
 
@@ -429,8 +427,10 @@ int main( int /*argc*/, const char ** /*argv*/ )
 		if ( saved && verify )
 		if ( saved && verify )
 		{
 		{
 			okay = 1;
 			okay = 1;
+			char verifyBuf[256];
 			while ( fgets( verifyBuf, 256, verify ) )
 			while ( fgets( verifyBuf, 256, verify ) )
 			{
 			{
+				char savedBuf[256];
 				fgets( savedBuf, 256, saved );
 				fgets( savedBuf, 256, saved );
 				NullLineEndings( verifyBuf );
 				NullLineEndings( verifyBuf );
 				NullLineEndings( savedBuf );
 				NullLineEndings( savedBuf );
@@ -568,8 +568,8 @@ int main( int /*argc*/, const char ** /*argv*/ )
 					 "<psg context=\"Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;."
 					 "<psg context=\"Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;."
 					 " It also has &lt;, &gt;, and &amp;, as well as a fake copyright \xC2\xA9.\"/>\n",
 					 " It also has &lt;, &gt;, and &amp;, as well as a fake copyright \xC2\xA9.\"/>\n",
 					 buf, false );
 					 buf, false );
+			fclose( textfile );
 		}
 		}
-		fclose( textfile );
 	}
 	}
 
 
 	{
 	{