From df29394ff491a525d1ba7c504686bae10393da12 Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Thu, 6 Feb 2020 15:28:30 +0900 Subject: [PATCH] [code cleanup] Add to check hard return value for file_read Change-Id: I329980a09b6be133d374376a6bbe7b833afcf271 --- formats/ffmpeg/mm_file_format_mp3.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/formats/ffmpeg/mm_file_format_mp3.c b/formats/ffmpeg/mm_file_format_mp3.c index 301bf47..15a7563 100644 --- a/formats/ffmpeg/mm_file_format_mp3.c +++ b/formats/ffmpeg/mm_file_format_mp3.c @@ -1031,21 +1031,21 @@ static int mmf_file_mp3_get_tag_info(char *filename, AvFileContentInfo *pInfo) } v2TagExistCheck = mmfile_malloc(MP3_TAGv2_HEADER_LEN); - if (v2TagExistCheck == NULL) { + if (!v2TagExistCheck) { debug_error(DEBUG, "malloc failed.\n"); goto EXCEPTION; } /* check ID3v2 header */ - if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) > 0) { - __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info); - mmfile_free(v2TagExistCheck); - } else { + if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) != MP3_TAGv2_HEADER_LEN) { debug_error(DEBUG, "v2TagExistCheck value read fail!\n"); mmfile_free(v2TagExistCheck); goto EXCEPTION; } + __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info); + mmfile_free(v2TagExistCheck); + if (mmfile_seek(hFile, 0L, SEEK_SET) < 0) goto EXCEPTION; @@ -1063,7 +1063,7 @@ static int mmf_file_mp3_get_tag_info(char *filename, AvFileContentInfo *pInfo) goto EXCEPTION; } - if (mmfile_read(hFile, buf, pInfo->tagV2Info.tagLen) <= 0) { + if (mmfile_read(hFile, buf, pInfo->tagV2Info.tagLen) != pInfo->tagV2Info.tagLen) { mmfile_free(buf); goto EXCEPTION; } @@ -1085,7 +1085,7 @@ static int mmf_file_mp3_get_tag_info(char *filename, AvFileContentInfo *pInfo) pInfo->bV1tagFound = false; /* read with TAG(ID3v1) length */ - if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) <= 0) + if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) != MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) goto EXCEPTION; /* check and get TAG(ID3v1) information */ @@ -1173,20 +1173,20 @@ static int mmf_file_mp3_get_stream_info(char *filename, AvFileContentInfo *pInfo } v2TagExistCheck = mmfile_malloc(MP3_TAGv2_HEADER_LEN); - if (v2TagExistCheck == NULL) { + if (!v2TagExistCheck) { debug_error(DEBUG, "malloc failed.\n"); goto EXCEPTION; } - if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) > 0) { - __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info); - mmfile_free(v2TagExistCheck); - } else { + if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) != MP3_TAGv2_HEADER_LEN) { debug_error(DEBUG, "v2TagExistCheck value read fail!\n"); mmfile_free(v2TagExistCheck); goto EXCEPTION; } + __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info); + mmfile_free(v2TagExistCheck); + if (mmfile_seek(hFile, 0L, SEEK_SET) < 0) goto EXCEPTION; @@ -1216,12 +1216,11 @@ static int mmf_file_mp3_get_stream_info(char *filename, AvFileContentInfo *pInfo goto EXCEPTION; } - if (mmfile_read(hFile, buf, bufLen) <= 0) { + if (mmfile_read(hFile, buf, bufLen) != (int)bufLen) { mmfile_free(buf); goto EXCEPTION; } - /* Is this needed? */ if (__AvGetLastID3v2offset(hFile, &head_offset)) { debug_msg(RELEASE, "search start offset: %u\n", head_offset); pInfo->tagV2Info.tagLen = head_offset; @@ -1241,10 +1240,10 @@ static int mmf_file_mp3_get_stream_info(char *filename, AvFileContentInfo *pInfo if (mmfile_seek(hFile, pInfo->headerPos, SEEK_SET) < 0) goto EXCEPTION; - if (mmfile_read(hFile, header, 256) <= 0) + if (mmfile_read(hFile, header, 256) != 256) goto EXCEPTION; - if (__AvParseMp3Header(pInfo, header) == false) + if (!__AvParseMp3Header(pInfo, header)) goto EXCEPTION; if (__AvParseXingHeader(pInfo, header) || __AvParseVBRIHeader(pInfo, header)) { @@ -1273,7 +1272,7 @@ static int mmf_file_mp3_get_stream_info(char *filename, AvFileContentInfo *pInfo pInfo->bV1tagFound = false; - if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) <= 0) + if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) != MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) goto EXCEPTION; if (__AvGetID3v1Header(TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP, NULL)) -- 2.7.4