rlottie: Fix all cppcheck warnings.
authorsubhransu mohanty <sub.mohanty@samsung.com>
Thu, 20 Jun 2019 00:10:09 +0000 (09:10 +0900)
committerHermet Park <hermetpark@gmail.com>
Tue, 25 Jun 2019 11:58:36 +0000 (20:58 +0900)
src/lottie/lottieitem.cpp
src/lottie/lottiemodel.h
src/lottie/lottieparser.cpp
src/vector/vpath.cpp
src/vector/vraster.cpp
src/vector/vrle.cpp

index d318dc0..f9e8f89 100644 (file)
@@ -93,23 +93,18 @@ LOTCompItem::createLayerItem(LOTLayerData *layerData)
     switch (layerData->mLayerType) {
     case LayerType::Precomp: {
         return std::make_unique<LOTCompLayerItem>(layerData);
-        break;
     }
     case LayerType::Solid: {
         return std::make_unique<LOTSolidLayerItem>(layerData);
-        break;
     }
     case LayerType::Shape: {
         return std::make_unique<LOTShapeLayerItem>(layerData);
-        break;
     }
     case LayerType::Null: {
         return std::make_unique<LOTNullLayerItem>(layerData);
-        break;
     }
     case LayerType::Image: {
         return std::make_unique<LOTImageLayerItem>(layerData);
-        break;
     }
     default:
         return nullptr;
@@ -859,9 +854,9 @@ LOTNullLayerItem::LOTNullLayerItem(LOTLayerData *layerData)
 void LOTNullLayerItem::updateContent() {}
 
 LOTShapeLayerItem::LOTShapeLayerItem(LOTLayerData *layerData)
-    : LOTLayerItem(layerData)
+    : LOTLayerItem(layerData),
+      mRoot(std::make_unique<LOTContentGroupItem>(nullptr))
 {
-    mRoot = std::make_unique<LOTContentGroupItem>(nullptr);
     mRoot->addChildren(layerData);
 
     std::vector<LOTPathDataItem *> list;
@@ -880,47 +875,36 @@ LOTShapeLayerItem::createContentItem(LOTData *contentData)
     case LOTData::Type::ShapeGroup: {
         return std::make_unique<LOTContentGroupItem>(
             static_cast<LOTGroupData *>(contentData));
-        break;
     }
     case LOTData::Type::Rect: {
         return std::make_unique<LOTRectItem>(static_cast<LOTRectData *>(contentData));
-        break;
     }
     case LOTData::Type::Ellipse: {
         return std::make_unique<LOTEllipseItem>(static_cast<LOTEllipseData *>(contentData));
-        break;
     }
     case LOTData::Type::Shape: {
         return std::make_unique<LOTShapeItem>(static_cast<LOTShapeData *>(contentData));
-        break;
     }
     case LOTData::Type::Polystar: {
         return std::make_unique<LOTPolystarItem>(static_cast<LOTPolystarData *>(contentData));
-        break;
     }
     case LOTData::Type::Fill: {
         return std::make_unique<LOTFillItem>(static_cast<LOTFillData *>(contentData));
-        break;
     }
     case LOTData::Type::GFill: {
         return std::make_unique<LOTGFillItem>(static_cast<LOTGFillData *>(contentData));
-        break;
     }
     case LOTData::Type::Stroke: {
         return std::make_unique<LOTStrokeItem>(static_cast<LOTStrokeData *>(contentData));
-        break;
     }
     case LOTData::Type::GStroke: {
         return std::make_unique<LOTGStrokeItem>(static_cast<LOTGStrokeData *>(contentData));
-        break;
     }
     case LOTData::Type::Repeater: {
         return std::make_unique<LOTRepeaterItem>(static_cast<LOTRepeaterData *>(contentData));
-        break;
     }
     case LOTData::Type::Trim: {
         return std::make_unique<LOTTrimItem>(static_cast<LOTTrimData *>(contentData));
-        break;
     }
     default:
         return nullptr;
index 6e7131f..5a63dc4 100644 (file)
@@ -360,7 +360,7 @@ public:
         Trim,
         Repeater
     };
-    LOTData(LOTData::Type  type): mType(type){}
+    explicit LOTData(LOTData::Type  type): mType(type){}
     inline LOTData::Type type() const {return mType;}
     bool isStatic() const{return mStatic;}
     void setStatic(bool value) {mStatic = value;}
@@ -376,7 +376,7 @@ public:
 class LOTGroupData: public LOTData
 {
 public:
-    LOTGroupData(LOTData::Type  type):LOTData(type){}
+    explicit LOTGroupData(LOTData::Type  type):LOTData(type){}
 public:
     std::vector<std::shared_ptr<LOTData>>  mChildren;
     std::shared_ptr<LOTTransformData>      mTransform;
@@ -671,7 +671,7 @@ inline LottieGradient operator*(float m, const LottieGradient &g)
 class LOTGradient : public LOTData
 {
 public:
-    LOTGradient(LOTData::Type  type):LOTData(type){}
+    explicit LOTGradient(LOTData::Type  type):LOTData(type){}
     inline float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;}
     void update(std::unique_ptr<VGradient> &grad, int frameNo);
 
@@ -719,7 +719,7 @@ public:
 class LOTPath : public LOTData
 {
 public:
-    LOTPath(LOTData::Type  type):LOTData(type){}
+    explicit LOTPath(LOTData::Type  type):LOTData(type){}
     VPath::Direction direction() { if (mDirection == 3) return VPath::Direction::CCW;
                                    else return VPath::Direction::CW;}
 public:
index ae84ba9..1b487db 100644 (file)
@@ -145,7 +145,7 @@ public:
     }
 
 protected:
-    LookaheadParserHandler(char *str);
+    explicit LookaheadParserHandler(char *str);
     void ParseNext();
 
 protected:
@@ -715,7 +715,7 @@ std::shared_ptr<LOTAsset> LottieParserImpl::parseAsset()
     if (asset->mAssetType == LOTAsset::Type::Image) {
         if (embededResource) {
             // embeder resource should start with "data:"
-            if (filename.find("data:", 0) == 0) {
+            if (filename.compare(0, 5,"data:") == 0) {
                 asset->loadImageData(convertFromBase64(filename));
             }
         } else {
@@ -832,7 +832,6 @@ std::shared_ptr<LOTData> LottieParserImpl::parseLayer(bool record)
     LOTLayerData *layer = sharedLayer.get();
     curLayerRef = layer;
     bool ddd = true;
-    std::string layerName;
     EnterObject();
     while (const char *key = NextObjectKey()) {
         if (0 == strcmp(key, "ty")) { /* Type of layer*/
index 225e57b..3d6dfd0 100644 (file)
@@ -524,8 +524,6 @@ void VPath::VPathData::addPolystar(float points, float innerRadius,
     float              currentAngle = (startAngle - 90.0) * M_PI / 180.0;
     float              x;
     float              y;
-    float              previousX;
-    float              previousY;
     float              partialPointRadius = 0;
     float              anglePerPoint = (float)(2.0 * M_PI / points);
     float              halfAnglePerPoint = anglePerPoint / 2.0;
@@ -573,8 +571,8 @@ void VPath::VPathData::addPolystar(float points, float innerRadius,
         if (partialPointRadius != 0 && i == numPoints - 1) {
             radius = partialPointRadius;
         }
-        previousX = x;
-        previousY = y;
+        float previousX = x;
+        float previousY = y;
         x = (float)(radius * cos(currentAngle));
         y = (float)(radius * sin(currentAngle));
 
@@ -632,8 +630,6 @@ void VPath::VPathData::addPolygon(float points, float radius, float roundness,
     float              currentAngle = (startAngle - 90.0) * M_PI / 180.0;
     float              x;
     float              y;
-    float              previousX;
-    float              previousY;
     float              anglePerPoint = (float)(2.0 * M_PI / floor(points));
     int                numPoints = (int)floor(points);
     float              angleDir = ((dir == VPath::Direction::CW) ? 1.0 : -1.0);
@@ -656,8 +652,8 @@ void VPath::VPathData::addPolygon(float points, float radius, float roundness,
     moveTo(x + cx, y + cy);
 
     for (int i = 0; i < numPoints; i++) {
-        previousX = x;
-        previousY = y;
+        float previousX = x;
+        float previousY = y;
         x = (float)(radius * cos(currentAngle));
         y = (float)(radius * sin(currentAngle));
 
index 63ea988..2d05443 100644 (file)
@@ -33,7 +33,7 @@ template<typename T>
 class dyn_array
 {
 public:
-    dyn_array(size_t size):mCapacity(size),mData(std::make_unique<T[]>(mCapacity)){}
+    explicit dyn_array(size_t size):mCapacity(size),mData(std::make_unique<T[]>(mCapacity)){}
     void reserve(size_t size)
     {
         if (mCapacity > size) return;
@@ -236,11 +236,6 @@ void FTOutline::end()
     }
 }
 
-struct SpanInfo {
-    VRle::Span *spans;
-    int         size;
-};
-
 static void rleGenerationCb(int count, const SW_FT_Span *spans, void *user)
 {
     VRle *      rle = (VRle *)user;
index 84e2758..c1dc9ba 100644 (file)
@@ -128,16 +128,16 @@ void VRle::VRleData::updateBbox() const
 
     mBboxDirty = false;
 
-    int i, l = 0, t = 0, r = 0, b = 0, sz;
-    l = std::numeric_limits<int>::max();
+    int l = std::numeric_limits<int>::max();
     const VRle::Span *span = mSpans.data();
 
     mBbox = VRect();
-    sz = mSpans.size();
+    size_t sz = mSpans.size();
     if (sz) {
-        t = span[0].y;
-        b = span[sz - 1].y;
-        for (i = 0; i < sz; i++) {
+        int t = span[0].y;
+        int b = span[sz - 1].y;
+        int r = 0;
+        for (size_t i = 0; i < sz; i++) {
             if (span[i].x < l) l = span[i].x;
             if (span[i].x + span[i].len > r) r = span[i].x + span[i].len;
         }
@@ -511,11 +511,10 @@ static void rleIntersectWithRect(const VRect &clip, VRleHelper *tmp_obj,
 void blitXor(VRle::Span *spans, int count, uchar *buffer,
                         int offsetX)
 {
-    uchar *ptr;
     while (count--) {
         int x = spans->x + offsetX;
         int l = spans->len;
-        ptr = buffer + x;
+        uchar *ptr = buffer + x;
         while (l--) {
             int da = *ptr;
             *ptr = divBy255((255 - spans->coverage) * (da) + spans->coverage * (255 - da));
@@ -528,11 +527,10 @@ void blitXor(VRle::Span *spans, int count, uchar *buffer,
 void blitDestinationOut(VRle::Span *spans, int count, uchar *buffer,
                         int offsetX)
 {
-    uchar *ptr;
     while (count--) {
         int x = spans->x + offsetX;
         int l = spans->len;
-        ptr = buffer + x;
+        uchar *ptr = buffer + x;
         while (l--) {
             *ptr = divBy255((255 - spans->coverage) * (*ptr));
             ptr++;
@@ -543,11 +541,10 @@ void blitDestinationOut(VRle::Span *spans, int count, uchar *buffer,
 
 void blitSrcOver(VRle::Span *spans, int count, uchar *buffer, int offsetX)
 {
-    uchar *ptr;
     while (count--) {
         int x = spans->x + offsetX;
         int l = spans->len;
-        ptr = buffer + x;
+        uchar *ptr = buffer + x;
         while (l--) {
             *ptr = spans->coverage + divBy255((255 - spans->coverage) * (*ptr));
             ptr++;
@@ -558,11 +555,10 @@ void blitSrcOver(VRle::Span *spans, int count, uchar *buffer, int offsetX)
 
 void blit(VRle::Span *spans, int count, uchar *buffer, int offsetX)
 {
-    uchar *ptr;
     while (count--) {
         int x = spans->x + offsetX;
         int l = spans->len;
-        ptr = buffer + x;
+        uchar *ptr = buffer + x;
         while (l--) {
             *ptr = std::max(spans->coverage, *ptr);
             ptr++;