diff --git a/code/ValidateDataStructure.cpp b/code/ValidateDataStructure.cpp index 3076b8fe3..9f1a41b8b 100644 --- a/code/ValidateDataStructure.cpp +++ b/code/ValidateDataStructure.cpp @@ -74,7 +74,7 @@ bool ValidateDSProcess::IsActive( unsigned int pFlags) const return (pFlags & aiProcess_ValidateDataStructure) != 0; } // ------------------------------------------------------------------------------------------------ -void ValidateDSProcess::ReportError(const char* msg,...) +AI_WONT_RETURN void ValidateDSProcess::ReportError(const char* msg,...) { ai_assert(NULL != msg); diff --git a/code/ValidateDataStructure.h b/code/ValidateDataStructure.h index 7a8124c08..8673e5829 100644 --- a/code/ValidateDataStructure.h +++ b/code/ValidateDataStructure.h @@ -58,9 +58,10 @@ struct aiString; namespace Assimp { -// --------------------------------------------------------------------------- -/** Validates the ASSIMP data structure - */ +// -------------------------------------------------------------------------------------- +/** Validates the whole ASSIMP scene data structure for correctness. + * ImportErrorException is thrown of the scene is corrupt.*/ +// -------------------------------------------------------------------------------------- class ASSIMP_API ValidateDSProcess : public BaseProcess { friend class Importer; @@ -84,55 +85,49 @@ protected: // ------------------------------------------------------------------- /** Report a validation error. This will throw an exception, * control won't return. - * @param msg Format string for sprintf(). - */ - void ReportError(const char* msg,...); + * @param msg Format string for sprintf().*/ + AI_WONT_RETURN void ReportError(const char* msg,...); + // ------------------------------------------------------------------- /** Report a validation warning. This won't throw an exception, * control will return to the callera. - * @param msg Format string for sprintf(). - */ + * @param msg Format string for sprintf().*/ void ReportWarning(const char* msg,...); + // ------------------------------------------------------------------- /** Validates a mesh - * @param pMesh Input mesh - */ + * @param pMesh Input mesh*/ void Validate( const aiMesh* pMesh); // ------------------------------------------------------------------- /** Validates a bone * @param pMesh Input mesh - * @param pBone Input bone - */ + * @param pBone Input bone*/ void Validate( const aiMesh* pMesh,const aiBone* pBone,float* afSum); // ------------------------------------------------------------------- /** Validates an animation - * @param pAnimation Input animation - */ + * @param pAnimation Input animation*/ void Validate( const aiAnimation* pAnimation); // ------------------------------------------------------------------- /** Validates a material - * @param pMaterial Input material - */ + * @param pMaterial Input material*/ void Validate( const aiMaterial* pMaterial); // ------------------------------------------------------------------- /** Search the material data structure for invalid or corrupt * texture keys. * @param pMaterial Input material - * @param type Type of the texture - */ + * @param type Type of the texture*/ void SearchForInvalidTextures(const aiMaterial* pMaterial, aiTextureType type); // ------------------------------------------------------------------- /** Validates a texture - * @param pTexture Input texture - */ + * @param pTexture Input texture*/ void Validate( const aiTexture* pTexture); // ------------------------------------------------------------------- @@ -143,28 +138,24 @@ protected: // ------------------------------------------------------------------- /** Validates a camera - * @param pCamera Input camera - */ + * @param pCamera Input camera*/ void Validate( const aiCamera* pCamera); // ------------------------------------------------------------------- /** Validates a bone animation channel * @param pAnimation Animation channel. - * @param pBoneAnim Input bone animation - */ + * @param pBoneAnim Input bone animation */ void Validate( const aiAnimation* pAnimation, const aiNodeAnim* pBoneAnim); // ------------------------------------------------------------------- /** Validates a node and all of its subnodes - * @param Node Input node - */ + * @param Node Input node*/ void Validate( const aiNode* pNode); // ------------------------------------------------------------------- /** Validates a string - * @param pString Input string - */ + * @param pString Input string*/ void Validate( const aiString* pString); private: diff --git a/code/aiAssert.cpp b/code/aiAssert.cpp index 29f4279d7..487345538 100644 --- a/code/aiAssert.cpp +++ b/code/aiAssert.cpp @@ -10,7 +10,7 @@ // Set a breakpoint using win32, else line, file and message will be returned and progam ends with // errrocode = 1 -void Assimp::aiAssert (const std::string &message, unsigned int uiLine, const std::string &file) +AI_WONT_RETURN void Assimp::aiAssert (const std::string &message, unsigned int uiLine, const std::string &file) { // moved expression testing out of the function and into the macro to avoid constructing // two std::string on every single ai_assert test diff --git a/include/aiAssert.h b/include/aiAssert.h index 21e806227..cb930d12e 100644 --- a/include/aiAssert.h +++ b/include/aiAssert.h @@ -14,11 +14,11 @@ namespace Assimp { //! \brief ASSIMP specific assertion test, only works in debug mode //! \param uiLine Line in file //! \param file Source file -void aiAssert(const std::string &message, unsigned int uiLine, const std::string &file); +AI_WONT_RETURN void aiAssert(const std::string &message, unsigned int uiLine, const std::string &file); //! \def ai_assert -//! \brief ASSIM specific assertion test +//! \brief ASSIMP specific assertion test #ifdef DEBUG # define ai_assert(expression) if( !(expression)) Assimp::aiAssert( #expression, __LINE__, __FILE__); #else diff --git a/include/aiDefines.h b/include/aiDefines.h index 5ae19c704..494a97a4e 100644 --- a/include/aiDefines.h +++ b/include/aiDefines.h @@ -119,11 +119,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # define ASSIMP_API # endif - /* Force the compiler to inline a function, if supported + /* Force the compiler to inline a function, if possible */ # define AI_FORCE_INLINE __forceinline + /* Tells the compiler that a function never returns. Used in code analysis + * to skip dead paths (e.g. after an assertion evaluated false). + */ +# define AI_WONT_RETURN __declspec(noreturn) #else + +# define AI_WONT_RETURN + # define ASSIMP_API # define AI_FORCE_INLINE inline #endif // (defined _MSC_VER) @@ -213,7 +220,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define AI_MATH_TWO_PI (AI_MATH_PI * 2.0) #define AI_MATH_HALF_PI (AI_MATH_PI * 0.5) -/* And this is to avoid endless (float) casts */ +/* And this is to avoid endless casts to float */ #define AI_MATH_PI_F (3.1415926538f) #define AI_MATH_TWO_PI_F (AI_MATH_PI_F * 2.0f) #define AI_MATH_HALF_PI_F (AI_MATH_PI_F * 0.5f) diff --git a/include/aiTypes.h b/include/aiTypes.h index 9f72ba517..553560851 100644 --- a/include/aiTypes.h +++ b/include/aiTypes.h @@ -247,7 +247,9 @@ struct aiString aiString(const aiString& rOther) : length(rOther.length) { - memcpy( data, rOther.data, rOther.length); + // Crop the string to the maximum length + length = length>=MAXLEN?MAXLEN-1:length; + memcpy( data, rOther.data, length); data[length] = '\0'; } @@ -255,6 +257,7 @@ struct aiString aiString(const std::string& pString) : length(pString.length()) { + length = length>=MAXLEN?MAXLEN-1:length; memcpy( data, pString.c_str(), length); data[length] = '\0'; } diff --git a/tools/assimp_view/assimp_view.h b/tools/assimp_view/assimp_view.h index fd431ea6b..3e1e9468d 100644 --- a/tools/assimp_view/assimp_view.h +++ b/tools/assimp_view/assimp_view.h @@ -47,15 +47,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // include resource definitions #include "resource.h" -// Include ASSIMP headers +// Include ASSIMP headers (XXX: do we really need all of them?) +#include "assimp.h" +#include "assimp.hpp" #include "aiAssert.h" #include "aiFileIO.h" #include "aiPostProcess.h" #include "aiScene.h" #include "IOSystem.h" #include "IOStream.h" -#include "assimp.h" -#include "assimp.hpp" #include "LogStream.h" #include "DefaultLogger.h"