Fixed SVACE and related issues in dali-scene-loader. 67/250267/1
authorGyörgy Straub <g.straub@partner.samsung.com>
Tue, 22 Dec 2020 13:50:36 +0000 (13:50 +0000)
committerGyörgy Straub <g.straub@partner.samsung.com>
Tue, 22 Dec 2020 13:50:36 +0000 (13:50 +0000)
- sprintf() replaced with snprintf() in gltf2-loader;
- ExceptionFlinger's destructor is marked as [[noreturn]]; other
  methods are marked noexcept(true);
- fixed the assertion in MeshDefinition::Blob::ApplyMinMax(), where
  either min or max can be empty, or they have to be the same size;

Change-Id: Ib05c2cde99fb3b3403c5993740fc2d72e2399f48

dali-scene-loader/public-api/gltf2-loader.cpp
dali-scene-loader/public-api/mesh-definition.cpp
dali-scene-loader/public-api/utils.cpp
dali-scene-loader/public-api/utils.h

index ed08a41..451060b 100644 (file)
@@ -903,13 +903,15 @@ float LoadBlendShapeKeyFrames(const std::string& path, const gt::Animation::Chan
   const float duration = LoadDataFromAccessors<float>(path, input, output, inputDataBuffer, outputDataBuffer);
 
   char weightNameBuffer[32];
-  char* const pWeightName = weightNameBuffer + sprintf(weightNameBuffer, "%s[", BLEND_SHAPE_WEIGHTS_UNIFORM.c_str());
+  auto prefixSize = snprintf(weightNameBuffer, sizeof(weightNameBuffer), "%s[", BLEND_SHAPE_WEIGHTS_UNIFORM.c_str());
+  char* const pWeightName = weightNameBuffer + prefixSize;
+  const auto remainingSize = sizeof(weightNameBuffer) - prefixSize;
   for (uint32_t weightIndex = 0u, endWeightIndex = channel.mSampler->mOutput->mCount / channel.mSampler->mInput->mCount; weightIndex < endWeightIndex; ++weightIndex)
   {
     AnimatedProperty& animatedProperty = properties[propertyIndex++];
 
     animatedProperty.mNodeName = nodeName;
-    sprintf(pWeightName, "%d]", weightIndex);
+    snprintf(pWeightName, remainingSize, "%d]", weightIndex);
     animatedProperty.mPropertyName = std::string(weightNameBuffer);
 
     animatedProperty.mKeyFrames = KeyFrames::New();
index 19d4544..9823295 100644 (file)
@@ -457,7 +457,7 @@ MeshDefinition::Accessor::Accessor(const MeshDefinition::Blob& blob,
 void MeshDefinition::Blob::ApplyMinMax(const std::vector<float>& min, const std::vector<float>& max,
   uint32_t count, float* values)
 {
-  DALI_ASSERT_DEBUG(max.empty() || max.size() == min.size());
+  DALI_ASSERT_DEBUG(max.size() == min.size() || max.size() * min.size() == 0);
   const auto numComponents = std::max(min.size(), max.size());
 
   using ClampFn = void(*)(const float*, const float*, uint32_t, float&);
index 773bf17..382e118 100644 (file)
@@ -35,7 +35,7 @@ namespace
 thread_local char sExceptionFlingerMessageBuffer[ExceptionFlinger::MESSAGE_BUFFER_SIZE]{};
 }
 
-char* ExceptionFlinger::GetMessageBuffer()
+char* ExceptionFlinger::GetMessageBuffer() noexcept(true)
 {
   return sExceptionFlingerMessageBuffer;
 }
index 09c30e1..3ab0c33 100644 (file)
@@ -41,7 +41,7 @@ namespace SceneLoader
 class DALI_SCENE_LOADER_API StreamBuffer : public std::basic_streambuf<char>
 {
 public:
-  StreamBuffer(char* buffer, size_t size)
+  StreamBuffer(char* buffer, size_t size) noexcept(true)
   {
     setp(buffer, buffer + size);
   }
@@ -57,12 +57,13 @@ class DALI_SCENE_LOADER_API ExceptionFlinger
 public:
   enum { MESSAGE_BUFFER_SIZE = 512 };
 
-  ExceptionFlinger(const char* location)
+  ExceptionFlinger(const char* location) noexcept(true)
   : mLocation(location),
     mStreamBuffer(GetMessageBuffer(), MESSAGE_BUFFER_SIZE - 1),
     mStream(&mStreamBuffer)
   {}
 
+  [[noreturn]]
   ~ExceptionFlinger() noexcept(false)
   {
     operator<<('\0');
@@ -70,14 +71,14 @@ public:
   }
 
   template <typename T>
-  ExceptionFlinger& operator<<(const T& rhs)
+  ExceptionFlinger& operator<<(const T& rhs) noexcept(true)
   {
     mStream << rhs;
     return *this;
   }
 
 private:
-  static char* GetMessageBuffer();
+  static char* GetMessageBuffer() noexcept(true);
 
   const char* mLocation;
   StreamBuffer mStreamBuffer;