Klockwork: remove unreachable code, check iterators 25/29925/1
authorKingsley Stephens <k.stephens@partner.samsung.com>
Wed, 5 Nov 2014 15:02:17 +0000 (15:02 +0000)
committerKingsley Stephens <k.stephens@partner.samsung.com>
Wed, 5 Nov 2014 15:02:17 +0000 (15:02 +0000)
Change-Id: I1f34a05504af3a286cbdc1408ed2f9bf38903458

dali/internal/common/blending-options.cpp
dali/internal/event/images/image-factory.cpp
dali/internal/render/renderers/scene-graph-image-renderer.cpp
dali/internal/update/resources/resource-manager.cpp
dali/public-api/object/property-map.cpp
dali/public-api/object/property-value.cpp

index a6ee233..181b8f6 100644 (file)
@@ -109,10 +109,6 @@ void StoreBlendingFactor( unsigned int& options, BlendingFactor::Type factor, in
     case BlendingFactor::ONE_MINUS_CONSTANT_ALPHA:
       options |= ( 14u << bitShift );
       break;
-
-    default:
-      DALI_ASSERT_ALWAYS( false && "Invalid BlendingFactor" );
-      break;
   }
 }
 
@@ -137,10 +133,6 @@ void StoreBlendingEquation( unsigned int& options, BlendingEquation::Type factor
     case BlendingEquation::REVERSE_SUBTRACT:
       options |= ( 2u << bitShift );
       break;
-
-    default:
-      DALI_ASSERT_ALWAYS( false && "Invalid BlendingEquation" );
-      break;
   }
 }
 
index 67e0895..3ebc715 100644 (file)
@@ -280,32 +280,35 @@ Request* ImageFactory::FindRequest( const std::string& filename, size_t hash, co
     // get cached request
     RequestIdMap::iterator foundRequestIter = mRequestCache.find( cachedReqId );
     DALI_ASSERT_DEBUG( foundRequestIter != mRequestCache.end() );
-    const Request& cachedRequest = *(foundRequestIter->second);
-    const ImageAttributes* storedAttributes = cachedRequest.attributes;
-
-    // compare attributes: NULL means default attributes
-    if( !attributes )
-    {
-      attributes = &ImageAttributes::DEFAULT_ATTRIBUTES;
-    }
-    if( !storedAttributes )
+    if( foundRequestIter != mRequestCache.end() )
     {
-      storedAttributes = &ImageAttributes::DEFAULT_ATTRIBUTES;
-    }
+      const Request& cachedRequest = *(foundRequestIter->second);
+      const ImageAttributes* storedAttributes = cachedRequest.attributes;
 
-    if( *attributes != *storedAttributes )
-    {
-      continue;
-    }
+      // compare attributes: NULL means default attributes
+      if( !attributes )
+      {
+        attributes = &ImageAttributes::DEFAULT_ATTRIBUTES;
+      }
+      if( !storedAttributes )
+      {
+        storedAttributes = &ImageAttributes::DEFAULT_ATTRIBUTES;
+      }
 
-    if( filename.compare( cachedRequest.url ) )
-    {
-      // hash collision, filenames don't match
-      continue;
-    }
+      if( *attributes != *storedAttributes )
+      {
+        continue;
+      }
+
+      if( filename.compare( cachedRequest.url ) )
+      {
+        // hash collision, filenames don't match
+        continue;
+      }
 
-    // we've found an exact match
-    return foundRequestIter->second;
+      // we've found an exact match
+      return foundRequestIter->second;
+    }
   }
 
   return NULL;
@@ -328,42 +331,45 @@ ResourceTicketPtr ImageFactory::FindCompatibleResource( const std::string& filen
       // get cached request
       RequestIdMap::iterator foundRequestIter = mRequestCache.find( cachedReqId );
       DALI_ASSERT_DEBUG( foundRequestIter != mRequestCache.end() );
-      Request& cachedRequest = *(foundRequestIter->second);
-      if( filename.compare( cachedRequest.url ) )
-      {
-        // hash collision, filenames don't match
-        continue;
-      }
-
-      if( !cachedRequest.resourceId )
-      {
-        continue;
-      }
-
-      ticket = mResourceClient.RequestResourceTicket( cachedRequest.resourceId );
-      if( !ticket )
-      {
-        cachedRequest.resourceId = 0;
-        continue;
-      }
-
-      DALI_ASSERT_DEBUG( ticket->GetTypePath().type->id == ResourceBitmap      ||
-                         ticket->GetTypePath().type->id == ResourceNativeImage ||
-                         ticket->GetTypePath().type->id == ResourceTargetImage );
-
-      // check for compatible ImageAttributes
-      const ImageAttributes& storedAttributes = static_cast<ImageTicket*>(ticket.Get())->GetAttributes();
-      if( !attr )
+      if( foundRequestIter != mRequestCache.end() )
       {
-        attr = &ImageAttributes::DEFAULT_ATTRIBUTES;
-      }
-
-      // in case both attributes are default or they are matching custom ones
-      if( CompareAttributes( *attr, storedAttributes ) )
-      {
-        // found compatible resource
-        foundCompatible = true;
-        break;
+        Request& cachedRequest = *(foundRequestIter->second);
+        if( filename.compare( cachedRequest.url ) )
+        {
+          // hash collision, filenames don't match
+          continue;
+        }
+
+        if( !cachedRequest.resourceId )
+        {
+          continue;
+        }
+
+        ticket = mResourceClient.RequestResourceTicket( cachedRequest.resourceId );
+        if( !ticket )
+        {
+          cachedRequest.resourceId = 0;
+          continue;
+        }
+
+        DALI_ASSERT_DEBUG( ticket->GetTypePath().type->id == ResourceBitmap      ||
+                           ticket->GetTypePath().type->id == ResourceNativeImage ||
+                           ticket->GetTypePath().type->id == ResourceTargetImage );
+
+        // check for compatible ImageAttributes
+        const ImageAttributes& storedAttributes = static_cast<ImageTicket*>(ticket.Get())->GetAttributes();
+        if( !attr )
+        {
+          attr = &ImageAttributes::DEFAULT_ATTRIBUTES;
+        }
+
+        // in case both attributes are default or they are matching custom ones
+        if( CompareAttributes( *attr, storedAttributes ) )
+        {
+          // found compatible resource
+          foundCompatible = true;
+          break;
+        }
       }
     } // for( it ...
   } // foundRequests.first
index 292cf66..90b8e8c 100644 (file)
@@ -73,26 +73,29 @@ void GenerateIntervals(std::vector<VertexToTextureCoord>& intervalList, int inte
   DALI_ASSERT_DEBUG(intervals > 0);
 
   std::vector<VertexToTextureCoord>::const_iterator iter = insertionList.begin();
-  std::vector<VertexToTextureCoord>::const_iterator end = insertionList.end()-1;
-
-  const float length = end->x - iter->x;
-  const float intervalSize = length / static_cast<float>(intervals);
-  float x = iter->x;
-
-  for(;iter!=end;++iter)
+  if( iter != insertionList.end() )
   {
-    float x0 = iter[0].x;
-    float u0 = iter[0].u;
-    float x1 = iter[1].x;
-    float u1 = iter[1].u;
+    std::vector<VertexToTextureCoord>::const_iterator end = insertionList.end()-1;
+
+    const float length = end->x - iter->x;
+    const float intervalSize = length / static_cast<float>(intervals);
+    float x = iter->x;
 
-    for(;x<x1;x+=intervalSize)
+    for(;iter!=end;++iter)
     {
-      float progress = (x - x0) / (x1 - x0);  // progress value between current interval and next.
-      float u = u0 + (u1 - u0) * progress;    // u 1D texture coordinate value for this x position.
-      intervalList.push_back( VertexToTextureCoord( x, u ) );
+      float x0 = iter[0].x;
+      float u0 = iter[0].u;
+      float x1 = iter[1].x;
+      float u1 = iter[1].u;
+
+      for(;x<x1;x+=intervalSize)
+      {
+        float progress = (x - x0) / (x1 - x0);  // progress value between current interval and next.
+        float u = u0 + (u1 - u0) * progress;    // u 1D texture coordinate value for this x position.
+        intervalList.push_back( VertexToTextureCoord( x, u ) );
+      }
+      intervalList.push_back( VertexToTextureCoord( x1, u1 ) );
     }
-    intervalList.push_back( VertexToTextureCoord( x1, u1 ) );
   }
 }
 
index c56833a..ac81b50 100644 (file)
@@ -886,8 +886,11 @@ void ResourceManager::SaveComplete(ResourceId id, ResourceTypeId type)
     {
       ShaderCacheIter shaderIter  = mImpl->mShaders.find(id);
       DALI_ASSERT_DEBUG( mImpl->mShaders.end() != shaderIter );
-      ShaderDataPtr shaderDataPtr = shaderIter->second;
-      std::vector<unsigned char>().swap(shaderDataPtr->buffer);
+      if( mImpl->mShaders.end() != shaderIter )
+      {
+        ShaderDataPtr shaderDataPtr = shaderIter->second;
+        std::vector<unsigned char>().swap(shaderDataPtr->buffer);
+      }
     }
   }
 }
@@ -1072,9 +1075,11 @@ void ResourceManager::DiscardDeadResources( BufferIndex updateBufferIndex )
       {
         MeshCacheIter mesh = mImpl->mMeshes.find(iter->first);
         DALI_ASSERT_DEBUG( mImpl->mMeshes.end() != mesh );
-
-        mImpl->mDiscardQueue.Add( updateBufferIndex, mesh->second );
-        mImpl->mMeshes.erase( mesh );
+        if( mImpl->mMeshes.end() != mesh )
+        {
+          mImpl->mDiscardQueue.Add( updateBufferIndex, mesh->second );
+          mImpl->mMeshes.erase( mesh );
+        }
       }
       break;
 
index 5c70cbf..0e11d8a 100644 (file)
@@ -134,10 +134,6 @@ const Property::Value& Property::Map::operator[]( const std::string& key ) const
   }
 
   DALI_ASSERT_ALWAYS( ! "Invalid Key" );
-
-  // Should not reach here
-  static Value value;
-  return value;
 }
 
 Property::Value& Property::Map::operator[]( const std::string& key )
index 1141062..b837baf 100644 (file)
@@ -698,10 +698,6 @@ Property::Value& Property::Value::GetValue(const std::string& key) const
 
   DALI_LOG_WARNING("Cannot find property map key %s", key.c_str());
   DALI_ASSERT_ALWAYS(!"Cannot find property map key");
-
-  // should never return this
-  static Property::Value null;
-  return null;
 }
 
 bool Property::Value::HasKey(const std::string& key) const
@@ -848,10 +844,6 @@ Property::Value& Property::Value::GetItem(const int index) const
 
 
   DALI_ASSERT_ALWAYS(!"Property value index not valid");
-
-  // should never return this
-  static Property::Value null;
-  return null;
 }
 
 Property::Value& Property::Value::GetItem(const int index, std::string& key) const