Replace SAFE_STRLCPY to mmfile_strdup 32/217632/7
authorjiyong.min <jiyong.min@samsung.com>
Wed, 13 Nov 2019 05:05:43 +0000 (14:05 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 5 Dec 2019 01:41:23 +0000 (10:41 +0900)
Change-Id: I81a8687b35b6066a7c6454e0af8242ec357b4f20

utils/mm_file_util_io.c
utils/mm_file_util_tag.c

index 98ae703..f59d6c3 100644 (file)
@@ -98,7 +98,6 @@ static int _mmfile_open(MMFileIOHandle **handle, struct MMFileIOFunc *Func, cons
 {
        MMFileIOHandle *pHandle = NULL;
        int err = 0;
-       int fileNameLen = 0;
 
        if (!handle || !Func || !filename || !Func->mmfile_open) {
                debug_error(DEBUG, "invalid param\n");
@@ -118,19 +117,16 @@ static int _mmfile_open(MMFileIOHandle **handle, struct MMFileIOFunc *Func, cons
        pHandle->iofunc = Func;
        pHandle->flags = flags;
        pHandle->privateData = NULL;
-       fileNameLen = strlen(filename);
 
-       debug_msg(RELEASE, "[%d, %s]\n", fileNameLen, filename);
+       debug_msg(RELEASE, "[%s]\n", filename);
 
-       pHandle->fileName = mmfile_malloc(fileNameLen + 1);
+       pHandle->fileName = mmfile_strdup(filename);
        if (!pHandle->fileName) {
                debug_error(DEBUG, "mmfile_malloc: pHandle->fileName\n");
                err = MMFILE_IO_FAILED;
                goto fail;
        }
 
-       SAFE_STRLCPY(pHandle->fileName, filename, fileNameLen + 1);
-
        err = Func->mmfile_open(pHandle, filename, flags);
        if (err < 0) {
                debug_error(DEBUG, "mmfile_open: pHandle->fileName\n");
index e28f68b..bf6686b 100644 (file)
@@ -218,7 +218,7 @@ enum spherical_video_metadata_elements_ids_le {
 
 #define GENRE_COUNT    149
 
-static const char *MpegAudio_Genre[GENRE_COUNT] = {"Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal",
+static const char * const MpegAudio_Genre[GENRE_COUNT] = {"Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal",
                                                                                                "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial",
                                                                                                "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk",
                                                                                                "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise",
@@ -3826,42 +3826,31 @@ void mm_file_id3tag_restore_content_info(AvFileContentInfo *pInfo)
 {
        char    *mpegAudioGenre = NULL/*, *tmpGenreForV1Tag = NULL*/;
        bool    bAdditionGenre = false /*, bMpegAudioFrame = false*/;
-       int mpegAudioFileLen = 0, idv2IntGenre = 148/*, tmpinx = 0, tmpinx2=0*/;
-       unsigned char genre = pInfo->genre;
+       int mpegAudioFileLen = 0, idv2IntGenre = GENRE_COUNT - 1/*, tmpinx = 0, tmpinx2=0*/;
 
        /* for Genre Info */
        if (pInfo->tagV2Info.bGenreMarked == false) {
                if (pInfo->bV1tagFound == true) {
-                       debug_msg(RELEASE, "Genre: %d\n", genre);
-
-                       if (genre > 147)
-                               genre = 148;
-
-                       if (MpegAudio_Genre[genre] != NULL) {
-                               pInfo->genreLen = strlen(MpegAudio_Genre[genre]);
-                               if (pInfo->genreLen > 0) {
-                                       /* Give space for NULL character. Hence added "+1" */
-                                       pInfo->pGenre = mmfile_malloc(sizeof(char) * (pInfo->genreLen + 1));
-                                       if (pInfo->pGenre) {
-                                               SAFE_STRLCPY(pInfo->pGenre, MpegAudio_Genre[genre], pInfo->genreLen + 1);
-                                       }
-                               }
-                       }
+                       debug_msg(RELEASE, "Genre: %d\n", pInfo->genre);
+
+                       if (pInfo->genre > GENRE_COUNT - 1)
+                               pInfo->genre = GENRE_COUNT - 1;
+
+                       pInfo->pGenre = mmfile_strdup(MpegAudio_Genre[pInfo->genre]);
+                       if (pInfo->pGenre)
+                               pInfo->genreLen = strlen(pInfo->pGenre);
+                       else
+                               debug_error(RELEASE, "Genre: memory allocation failed.\n");
                } else {
                        debug_msg(RELEASE, "Genre was not Found.\n");
                }
        } else if (pInfo->tagV2Info.bGenreMarked == true) {
                debug_msg(RELEASE, "pInfo->genreLen size is Zero Or not UTF16 code! genreLen[%d] genre[%s]\n", pInfo->genreLen, pInfo->pGenre);
 
-               if (pInfo->pGenre) {
-                       pInfo->genreLen = strlen(pInfo->pGenre);
-                       mpegAudioGenre = mmfile_malloc(sizeof(char) * (pInfo->genreLen + 1));
-                       if (mpegAudioGenre != NULL) {
-                               SAFE_STRLCPY(mpegAudioGenre, pInfo->pGenre, pInfo->genreLen + 1);
-                       }
-               } else {
+               if (pInfo->pGenre)
+                       mpegAudioGenre = mmfile_strdup(pInfo->pGenre);
+               else
                        pInfo->genreLen = 0;
-               }
 
                mmfile_free(pInfo->pGenre);
 
@@ -3886,19 +3875,15 @@ void mm_file_id3tag_restore_content_info(AvFileContentInfo *pInfo)
                        if (bAdditionGenre == true) {
                                idv2IntGenre = atoi(mpegAudioGenre + 1);
 
-                               if (idv2IntGenre > 147 || idv2IntGenre < 0)
-                                       idv2IntGenre = 148;
+                               if (idv2IntGenre > GENRE_COUNT - 1 || idv2IntGenre < 0)
+                                       idv2IntGenre = GENRE_COUNT - 1;
+
+                               pInfo->pGenre = mmfile_strdup(MpegAudio_Genre[idv2IntGenre]);
+                               if (pInfo->pGenre)
+                                       pInfo->genreLen = strlen(pInfo->pGenre);
+                               else
+                                       debug_error(RELEASE, "Genre: memory allocation failed.\n");
 
-                               if (MpegAudio_Genre[idv2IntGenre] != NULL) {
-                                       pInfo->genreLen = strlen(MpegAudio_Genre[idv2IntGenre]);
-                                       if (pInfo->genreLen > 0) {
-                                               /* Give space for NULL character. Hence added "+1" */
-                                               pInfo->pGenre = mmfile_malloc(sizeof(char) * (pInfo->genreLen + 1));
-                                               if (pInfo->pGenre) {
-                                                       SAFE_STRLCPY(pInfo->pGenre, MpegAudio_Genre[idv2IntGenre], pInfo->genreLen + 1);
-                                               }
-                                       }
-                               }
                                debug_msg(RELEASE, "pInfo->pGenre = %s\n", pInfo->pGenre);
                        } else if (bAdditionGenre == false && pInfo->genreLen > 0) {
                                /**
@@ -3906,10 +3891,12 @@ void mm_file_id3tag_restore_content_info(AvFileContentInfo *pInfo)
                                 */
 
                                /* Give space for NULL character. Hence added "+1" */
-                               pInfo->pGenre = mmfile_malloc(sizeof(char) * (pInfo->genreLen + 1));
-                               if (pInfo->pGenre) {
-                                       SAFE_STRLCPY(pInfo->pGenre, mpegAudioGenre, pInfo->genreLen + 1);
-                               }
+                               pInfo->pGenre = mmfile_strdup(mpegAudioGenre);
+                               if (pInfo->pGenre)
+                                       pInfo->genreLen = strlen(pInfo->pGenre);
+                               else
+                                       debug_error(RELEASE, "Genre: memory allocation failed.\n");
+
                                debug_msg(RELEASE, "pInfo->pGenre = %s, pInfo->genreLen = %d\n", pInfo->pGenre, pInfo->genreLen);
                        } else {
                                debug_msg(RELEASE, "Failed to \"(...)\" value to genre = %s\n", pInfo->pGenre);
@@ -3918,7 +3905,6 @@ void mm_file_id3tag_restore_content_info(AvFileContentInfo *pInfo)
                        debug_msg(RELEASE, "mpegAudioGenre = %s\n", mpegAudioGenre);
                }
                mmfile_free(mpegAudioGenre);
-
        } else {
                debug_msg(RELEASE, "Neither ID3 v1 nor v2 info doesn't have Genre Info.\n");
        }