Fixed the SVACE issue in ExceptionFlinger. 28/250328/2
authorGyörgy Straub <g.straub@partner.samsung.com>
Wed, 23 Dec 2020 11:29:58 +0000 (11:29 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 23 Dec 2020 12:23:34 +0000 (12:23 +0000)
This ensures that the exception is only thrown following the destruction
of all other data members.

Change-Id: Ice35cc81130a056c168e7124b0277ec32a9526ce
Signed-off-by: György Straub <g.straub@partner.samsung.com>
dali-scene-loader/public-api/utils.cpp
dali-scene-loader/public-api/utils.h

index dbfb8e8..8b8132e 100644 (file)
@@ -40,8 +40,13 @@ StreamBuffer::StreamBuffer(char* buffer, size_t size) noexcept(true)
   setp(buffer, buffer + size);
 }
 
+ExceptionFlinger::Impl::~Impl() noexcept(false)
+{
+  throw DaliException(mLocation, GetMessageBuffer());
+}
+
 ExceptionFlinger::ExceptionFlinger(const char* location) noexcept(true)
-: mLocation(location),
+: mImpl{ location },
   mStreamBuffer(GetMessageBuffer(), MESSAGE_BUFFER_SIZE - 1),
   mStream(&mStreamBuffer)
 {}
@@ -49,7 +54,6 @@ ExceptionFlinger::ExceptionFlinger(const char* location) noexcept(true)
 ExceptionFlinger::~ExceptionFlinger() noexcept(false)
 {
   operator<<('\0');
-  throw DaliException(mLocation, GetMessageBuffer());
 }
 
 char* ExceptionFlinger::GetMessageBuffer() noexcept(true)
index 70009a2..1aace35 100644 (file)
@@ -67,9 +67,17 @@ public:
   }
 
 private:
+  struct Impl
+  {
+    const char* mLocation;
+
+    [[noreturn]]
+    ~Impl() noexcept(false);
+  };
+
   static char* GetMessageBuffer() noexcept(true);
 
-  const char* mLocation;
+  Impl mImpl;
   StreamBuffer mStreamBuffer;
   std::ostream mStream;
 };