From: jiyong.min Date: Mon, 28 Jan 2019 08:23:39 +0000 (+0900) Subject: Add to check the return of fseek() X-Git-Tag: accepted/tizen/unified/20190207.120252^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7a2a5ee7dc07aa145b41971202bc676c4b1f99b8;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Add to check the return of fseek() - If fseek() is failed, -1 is returned and errno is set to indicate the errors. Change-Id: Id5cc540e185d310d287c417160ca321f4322a5a4 --- diff --git a/bmp/test/mm_util_bmp_testsuite.c b/bmp/test/mm_util_bmp_testsuite.c old mode 100755 new mode 100644 index 5a6ba41..7a062ee --- a/bmp/test/mm_util_bmp_testsuite.c +++ b/bmp/test/mm_util_bmp_testsuite.c @@ -82,7 +82,12 @@ static gboolean _read_file(char *path, void **data, size_t *length) return FALSE; } - fseek(fp, 0, SEEK_END); + if (fseek(fp, 0, SEEK_END) < 0) { + fprintf(stderr, "\t[BMP_testsuite] fseek failed \n"); + fclose(fp); + return FALSE; + } + len = ftell(fp); if (len < 0) { fprintf(stderr, "\t[BMP_testsuite] ftell failed \n"); diff --git a/bmp/unittest/FileInterface.cpp b/bmp/unittest/FileInterface.cpp index 8dbbdee..cf8c8bf 100644 --- a/bmp/unittest/FileInterface.cpp +++ b/bmp/unittest/FileInterface.cpp @@ -43,7 +43,9 @@ void FileInterface::Open(const char *path) long size = 0; - fseek(fp, 0, SEEK_END); + if (fseek(fp, 0, SEEK_END) < 0) + return ; + size = (size_t)ftell(fp); rewind(fp); diff --git a/gif/unittest/FileInterface.cpp b/gif/unittest/FileInterface.cpp index 8dbbdee..cf8c8bf 100644 --- a/gif/unittest/FileInterface.cpp +++ b/gif/unittest/FileInterface.cpp @@ -43,7 +43,9 @@ void FileInterface::Open(const char *path) long size = 0; - fseek(fp, 0, SEEK_END); + if (fseek(fp, 0, SEEK_END) < 0) + return ; + size = (size_t)ftell(fp); rewind(fp); diff --git a/imgp/test/mm_util_imgp_testsuite.c b/imgp/test/mm_util_imgp_testsuite.c old mode 100755 new mode 100644 index 3f721ce..a67124e --- a/imgp/test/mm_util_imgp_testsuite.c +++ b/imgp/test/mm_util_imgp_testsuite.c @@ -49,7 +49,12 @@ static gboolean _read_file(char *path, void **data, size_t *length) return FALSE; } - fseek(fp, 0, SEEK_END); + if (fseek(fp, 0, SEEK_END) < 0) { + fprintf(stderr, "\t[JPEG_testsuite] fseek failed \n"); + fclose(fp); + return FALSE; + } + len = ftell(fp); if (len < 0) { fprintf(stderr, "\t[JPEG_testsuite] ftell failed \n"); diff --git a/jpeg/test/mm_util_jpeg_testsuite.c b/jpeg/test/mm_util_jpeg_testsuite.c old mode 100755 new mode 100644 index 19496bd..5bdf8ca --- a/jpeg/test/mm_util_jpeg_testsuite.c +++ b/jpeg/test/mm_util_jpeg_testsuite.c @@ -85,7 +85,12 @@ static gboolean _read_file(char *path, void **data, size_t *length) return FALSE; } - fseek(fp, 0, SEEK_END); + if (fseek(fp, 0, SEEK_END) < 0) { + fprintf(stderr, "\t[JPEG_testsuite] fseek failed \n"); + fclose(fp); + return FALSE; + } + len = ftell(fp); if (len < 0) { fprintf(stderr, "\t[JPEG_testsuite] ftell failed \n"); diff --git a/jpeg/unittest/FileInterface.cpp b/jpeg/unittest/FileInterface.cpp index 8dbbdee..cf8c8bf 100644 --- a/jpeg/unittest/FileInterface.cpp +++ b/jpeg/unittest/FileInterface.cpp @@ -43,7 +43,9 @@ void FileInterface::Open(const char *path) long size = 0; - fseek(fp, 0, SEEK_END); + if (fseek(fp, 0, SEEK_END) < 0) + return ; + size = (size_t)ftell(fp); rewind(fp); diff --git a/magick/mm_util_info.c b/magick/mm_util_info.c index af2d00a..8e63a22 100755 --- a/magick/mm_util_info.c +++ b/magick/mm_util_info.c @@ -49,8 +49,10 @@ void __ImgGetFileAttributes(const char *szPathName, unsigned long *pFileAttr) f = fopen(szPathName, "r"); if (f != NULL) { - fseek(f, 0, SEEK_END); - *pFileAttr = ftell(f); + if (fseek(f, 0, SEEK_END) < 0) + mm_util_stderror("fseek failed"); + else + *pFileAttr = ftell(f); fclose(f); } } @@ -108,7 +110,7 @@ static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, unsigned long long i = 4; if (fseek(hFile, block_length + 4, SEEK_CUR) < 0) { - mm_util_error("fseek was failed"); + mm_util_stderror("fseek failed"); return MM_UTIL_ERROR_INVALID_OPERATION; } @@ -147,7 +149,7 @@ static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, mm_util_sec_debug("new block length : %u", block_length); if (fseek(hFile, block_length - JPG_BLOCK_SIZE_LENGTH, SEEK_CUR) < 0) { - mm_util_error("fseek was failed"); + mm_util_stderror("fseek failed"); return MM_UTIL_ERROR_INVALID_OPERATION; } } @@ -261,7 +263,9 @@ int mm_util_extract_image_info(const char *path, mm_util_img_codec_type *type, u ret = _ImgGetImageInfo(hFile, file_size, file_ext, type, width, height); - fseek(hFile, 0, SEEK_SET); + if (fseek(hFile, 0, SEEK_SET) < 0) + mm_util_stderror("fseek failed"); + fclose(hFile); return ret; diff --git a/png/test/mm_util_png_testsuite.c b/png/test/mm_util_png_testsuite.c old mode 100755 new mode 100644 index 6d6512d..44851d7 --- a/png/test/mm_util_png_testsuite.c +++ b/png/test/mm_util_png_testsuite.c @@ -83,7 +83,12 @@ static gboolean _read_file(char *path, void **data, size_t *length) return FALSE; } - fseek(fp, 0, SEEK_END); + if (fseek(fp, 0, SEEK_END) < 0) { + fprintf(stderr, "\t[PNG_testsuite] fseek failed \n"); + fclose(fp); + return FALSE; + } + len = ftell(fp); if (len < 0) { fprintf(stderr, "\t[PNG_testsuite] ftell failed \n"); diff --git a/png/unittest/FileInterface.cpp b/png/unittest/FileInterface.cpp index 8dbbdee..cf8c8bf 100644 --- a/png/unittest/FileInterface.cpp +++ b/png/unittest/FileInterface.cpp @@ -43,7 +43,9 @@ void FileInterface::Open(const char *path) long size = 0; - fseek(fp, 0, SEEK_END); + if (fseek(fp, 0, SEEK_END) < 0) + return ; + size = (size_t)ftell(fp); rewind(fp);