From ca698c3e491a5681c1959a61e944a1a267158373 Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Thu, 13 May 2021 09:36:42 +0100 Subject: [PATCH] Log error --- code/Common/DefaultLogger.cpp | 9 ++++---- code/PostProcessing/CalcTangentsProcess.cpp | 2 +- include/assimp/Logger.hpp | 23 ++++++++++++--------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/code/Common/DefaultLogger.cpp b/code/Common/DefaultLogger.cpp index a5c378e03..e468d72ca 100644 --- a/code/Common/DefaultLogger.cpp +++ b/code/Common/DefaultLogger.cpp @@ -176,7 +176,6 @@ void Logger::debug(const char *message) { // ---------------------------------------------------------------------------------- void Logger::verboseDebug(const char *message) { - // SECURITY FIX: otherwise it's easy to produce overruns since // sometimes importers will include data from the input file // (i.e. node names) in their messages. @@ -209,12 +208,14 @@ void Logger::warnInternal(Assimp::Formatter::format f) { } // ---------------------------------------------------------------------------------- -void Logger::error(const char *message) { +void Logger::errorInternal(Assimp::Formatter::format f) { + std::string message = f; + // TODO: Should limit sizes in the formatter. // SECURITY FIX: see above - if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) { + if (message.length() > MAX_LOG_MESSAGE_LENGTH) { return; } - return OnError(message); + return OnError(message.c_str()); } // ---------------------------------------------------------------------------------- diff --git a/code/PostProcessing/CalcTangentsProcess.cpp b/code/PostProcessing/CalcTangentsProcess.cpp index cdafda3b6..721567857 100644 --- a/code/PostProcessing/CalcTangentsProcess.cpp +++ b/code/PostProcessing/CalcTangentsProcess.cpp @@ -129,7 +129,7 @@ bool CalcTangentsProcess::ProcessMesh(aiMesh *pMesh, unsigned int meshIndex) { return false; } if (configSourceUV >= AI_MAX_NUMBER_OF_TEXTURECOORDS || !pMesh->mTextureCoords[configSourceUV]) { - ASSIMP_LOG_ERROR((Formatter::format("Failed to compute tangents; need UV data in channel"), configSourceUV)); + ASSIMP_LOG_ERROR_F("Failed to compute tangents; need UV data in channel", configSourceUV); return false; } diff --git a/include/assimp/Logger.hpp b/include/assimp/Logger.hpp index 2c3ee1085..07a26c053 100644 --- a/include/assimp/Logger.hpp +++ b/include/assimp/Logger.hpp @@ -128,9 +128,11 @@ public: // ---------------------------------------------------------------------- /** @brief Writes an error message - * @param message Error message*/ - void error(const char* message); - void error(const std::string &message); + * @param message Info message*/ + template + void error(T&&... args) { + errorInternal(Assimp::Formatter::format(), std::forward(args)...); + } // ---------------------------------------------------------------------- /** @brief Set a new log severity. @@ -244,6 +246,13 @@ protected: infoInternal(std::move(f << std::forward(u)), std::forward(args)...); } + void errorInternal(Assimp::Formatter::format f); + + template + void errorInternal(Assimp::Formatter::format f, U&& u, T&&... args) { + errorInternal(std::move(f << std::forward(u)), std::forward(args)...); + } + protected: LogSeverity m_Severity; }; @@ -296,12 +305,6 @@ inline void Logger::verboseDebug(const std::string &message) { return verboseDebug(message.c_str()); } -// ---------------------------------------------------------------------------------- -inline -void Logger::error(const std::string &message) { - return error(message.c_str()); -} - } // Namespace Assimp // ------------------------------------------------------------------------------------------------ @@ -309,7 +312,7 @@ void Logger::error(const std::string &message) { Assimp::DefaultLogger::get()->warn((string, __VA_ARGS__)) #define ASSIMP_LOG_ERROR_F(string, ...) \ - Assimp::DefaultLogger::get()->error((Assimp::Formatter::format(string), __VA_ARGS__)) + Assimp::DefaultLogger::get()->error((string, __VA_ARGS__)) #define ASSIMP_LOG_DEBUG_F(string, ...) \ Assimp::DefaultLogger::get()->debug((Assimp::Formatter::format(string), __VA_ARGS__))