From e4894f7da93ca9e5b541728dfa73fedfd6026c8e Mon Sep 17 00:00:00 2001 From: IceMage144 Date: Wed, 16 Aug 2017 17:50:33 -0300 Subject: [PATCH 1/2] Changed const char * to std::string Signed off by: @victordomiciano Signed off by: @kazuo256 Signed off by: @josealvim --- modules/ugdk-core/include/ugdk/system/exceptions.h | 4 ++-- modules/ugdk-core/src/system/exceptions.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ugdk-core/include/ugdk/system/exceptions.h b/modules/ugdk-core/include/ugdk/system/exceptions.h index d13bc8d9..5cd0c757 100644 --- a/modules/ugdk-core/include/ugdk/system/exceptions.h +++ b/modules/ugdk-core/include/ugdk/system/exceptions.h @@ -8,7 +8,7 @@ namespace system { class BaseException { public: - BaseException(const char * fmt, ...); + BaseException(const std::string& fmt, ...); virtual ~BaseException() throw() {} inline virtual const char * what() const throw() { @@ -34,4 +34,4 @@ void AssertCondition(bool condition, Args... args) { } // namespace system } // namespace ugdk -#endif // UGDK_SYSTEM_EXCEPTIONS_H_ \ No newline at end of file +#endif // UGDK_SYSTEM_EXCEPTIONS_H_ diff --git a/modules/ugdk-core/src/system/exceptions.cc b/modules/ugdk-core/src/system/exceptions.cc index e21ee800..66b5167c 100644 --- a/modules/ugdk-core/src/system/exceptions.cc +++ b/modules/ugdk-core/src/system/exceptions.cc @@ -28,7 +28,7 @@ namespace ugdk { namespace system { -BaseException::BaseException(const char * fmt, ...) +BaseException::BaseException(const std::string& fmt, ...) { va_list args; int size_buffer = 256, size_out; @@ -39,7 +39,7 @@ BaseException::BaseException(const char * fmt, ...) memset(buffer, 0, size_buffer); va_start(args, fmt); - size_out = vsnprintf(buffer, size_buffer, fmt, args); + size_out = vsnprintf(buffer, size_buffer, fmt.c_str(), args); va_end(args); // see http://perfec.to/vsnprintf/pasprintf.c From 5dde8a521c4b93ae5afe5e294215466708c3c73e Mon Sep 17 00:00:00 2001 From: Kazuo256 Date: Mon, 21 Aug 2017 16:12:27 -0300 Subject: [PATCH 2/2] Moved vsnprintf call in BaseException to private method Signed off by: @josealvim Signed off by: @icemage144 --- modules/ugdk-core/include/ugdk/system/exceptions.h | 6 +++++- modules/ugdk-core/src/system/exceptions.cc | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/ugdk-core/include/ugdk/system/exceptions.h b/modules/ugdk-core/include/ugdk/system/exceptions.h index 5cd0c757..48afd815 100644 --- a/modules/ugdk-core/include/ugdk/system/exceptions.h +++ b/modules/ugdk-core/include/ugdk/system/exceptions.h @@ -8,7 +8,10 @@ namespace system { class BaseException { public: - BaseException(const std::string& fmt, ...); + template + BaseException(const std::string& fmt, Args... args) { + set_reason(fmt.c_str(), args...); + } virtual ~BaseException() throw() {} inline virtual const char * what() const throw() { @@ -17,6 +20,7 @@ class BaseException { private: std::string reason_; + void set_reason(const char* fmt, ...); }; class InvalidOperation : public BaseException { diff --git a/modules/ugdk-core/src/system/exceptions.cc b/modules/ugdk-core/src/system/exceptions.cc index 66b5167c..0dc4f0fc 100644 --- a/modules/ugdk-core/src/system/exceptions.cc +++ b/modules/ugdk-core/src/system/exceptions.cc @@ -28,8 +28,7 @@ namespace ugdk { namespace system { -BaseException::BaseException(const std::string& fmt, ...) -{ +void BaseException::set_reason(const char* fmt, ...) { va_list args; int size_buffer = 256, size_out; char * buffer; @@ -39,7 +38,7 @@ BaseException::BaseException(const std::string& fmt, ...) memset(buffer, 0, size_buffer); va_start(args, fmt); - size_out = vsnprintf(buffer, size_buffer, fmt.c_str(), args); + size_out = vsnprintf(buffer, size_buffer, fmt, args); va_end(args); // see http://perfec.to/vsnprintf/pasprintf.c