Reinforce coverage 24/153624/1 accepted/tizen/unified/20171012.191742 submit/tizen/20171012.055141
authorMinje Ahn <minje.ahn@samsung.com>
Fri, 29 Sep 2017 03:06:35 +0000 (12:06 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Fri, 29 Sep 2017 03:06:35 +0000 (12:06 +0900)
Change-Id: I387ff9ec8c67a0cfc8ec787a81d42a80b33a4168
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/metadata_editor.cpp

index 5953d9d..7d4004e 100755 (executable)
@@ -21,6 +21,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <glib.h>
 
 static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value);
 static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value);
@@ -576,13 +577,10 @@ static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value)
        TagLib::MP4::ItemListMap& itemMap = tag->itemListMap();
        TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr");
        if (it != itemMap.end()) {                                                              // Item was found
-               uint number = it->second.toCoverArtList().size();                       // Get the size of CoverList (i.e. number of pictures in file)
-               metadata_editor_info("There are %u picture(s) in file", number);
                char buf[META_MAX_BUF_LEN] = {0, };
-               snprintf(buf, META_MAX_BUF_LEN, "%u", number);                                  // Convert integer value of size to its c-string representation
-               int length = strlen(buf);
-               metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string");
-               *value = strndup(buf, length);
+               snprintf(buf, META_MAX_BUF_LEN, "%u", it->second.toCoverArtList().size());      // Convert integer value of size to its c-string representation
+               if (strlen(buf) > 0)
+                       *value = g_strdup(buf);
                return METADATA_EDITOR_ERROR_NONE;
        } else {                                                                                // Item was not found
                metadata_editor_info("No item <covr> in file");
@@ -1398,14 +1396,11 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) {
                        if (!tag1 || tag1->isEmpty()) {                                                 // If no ID3v1 tag - prevent its creation
                                if (_file->save(TagLib::MPEG::File::ID3v2 | TagLib::MPEG::File::APE))
                                        return METADATA_EDITOR_ERROR_NONE;
-                               else
-                                       return METADATA_EDITOR_ERROR_OPERATION_FAILED;
                        } else {                                                                                // otherwise - save all tags in file
                                if (_file->save(TagLib::MPEG::File::AllTags))
                                        return METADATA_EDITOR_ERROR_NONE;
-                               else
-                                       return METADATA_EDITOR_ERROR_OPERATION_FAILED;
                        }
+                       return METADATA_EDITOR_ERROR_OPERATION_FAILED;
                }
                case METADATA_EDITOR_FORMAT_MP4: {
                        TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file;
@@ -1811,26 +1806,19 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in
                        metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating");
                        TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"];
                        // Check if there are pictures in the tag
-                       if (lst.isEmpty()) {
-                               metadata_editor_error("No pictures in file");
-                               return METADATA_EDITOR_ERROR_OPERATION_FAILED;
-                       } else {                // pictures exist in file
-                               // Check if index is correct or not
-                               if ((index < 0) || (lst.size() <= (uint)index)) {
-                                       metadata_editor_error("Index of picture is out of range");
-                                       return METADATA_EDITOR_ERROR_INVALID_PARAMETER;
-                               } else {                // everything is correct - begin extraction
-                                       metadata_editor_info("Removing of picture number %d", index);
-                                       int i = 0;
-                                       // Among all frames we must choose that one with specified index. "i" will be counter
-                                       for (TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) {
-                                               if (i != index) continue;
-                                               tag2->removeFrame(*it);
-                                               break;
-                                       }
-                                       return METADATA_EDITOR_ERROR_NONE;
-                               }
+                       metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_OPERATION_FAILED, "No pictures in file");
+
+                       // Check if index is correct or not
+                       metadata_editor_retvm_if((index < 0) || (lst.size() <= (uint)index), METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Index of picture is out of range");
+                       metadata_editor_info("Removing of picture number %d", index);
+                       int i = 0;
+                       // Among all frames we must choose that one with specified index. "i" will be counter
+                       for (TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) {
+                               if (i != index) continue;
+                               tag2->removeFrame(*it);
+                               break;
                        }
+                       return METADATA_EDITOR_ERROR_NONE;
                }
                case METADATA_EDITOR_FORMAT_MP4: {
                        TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file;