Skip to content

Commit

Permalink
[Encode] Fix some coverity issues exposed in encode
Browse files Browse the repository at this point in the history
Fix some remaining encode coverity issues: 1 Unchecked return value; 1 Resource leak; 2 Modulo by zero

Signed-off-by: Chen, Bohan <bohan.chen@intel.com>
  • Loading branch information
Bossonor authored and XinfengZhang committed Dec 5, 2023
1 parent 9bdec99 commit 715a03f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions encode/av1encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,9 @@ static int calc_PSNR(double *psnr)
srcyuv_ptr = mmap(0, fourM, PROT_READ, MAP_SHARED, fileno(srcyuv_fp), i);
recyuv_ptr = mmap(0, fourM, PROT_READ, MAP_SHARED, fileno(recyuv_fp), i);
if ((srcyuv_ptr == MAP_FAILED) || (recyuv_ptr == MAP_FAILED)) {
if (srcyuv_ptr)
if (srcyuv_ptr != MAP_FAILED)
munmap(srcyuv_ptr, fourM);
if (recyuv_ptr)
if (recyuv_ptr != MAP_FAILED)
munmap(recyuv_ptr, fourM);
printf("Failed to mmap YUV files\n");
return 1;
Expand Down
7 changes: 6 additions & 1 deletion encode/avcenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,12 @@ int main(int argc, char *argv[])
file_size = ftello(yuv_fp);
frame_size = picture_width * picture_height + ((picture_width * picture_height) >> 1) ;

if ((file_size < frame_size) || ((frame_size != 0) && (file_size % frame_size))) {
if (frame_size == 0) {
fclose(yuv_fp);
printf("Frame size is not correct\n");
return -1;
}
if ((file_size < frame_size) || (file_size % frame_size)) {
fclose(yuv_fp);
printf("The YUV file's size is not correct\n");
return -1;
Expand Down
14 changes: 13 additions & 1 deletion encode/hevcencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
exit(1); \
}

#define CHECK_CONDITION(cond) \
if(!(cond)) \
{ \
fprintf(stderr, "Unexpected condition: %s:%d\n", __func__, __LINE__);\
exit(1); \
}

#include "loadsurface.h"

#define NAL_REF_IDC_NONE 0
Expand Down Expand Up @@ -1920,7 +1927,8 @@ static int process_cmdline(int argc, char *argv[])
else {
struct stat tmp;

fstat(fileno(srcyuv_fp), &tmp);
int ret = fstat(fileno(srcyuv_fp), &tmp);
CHECK_CONDITION(ret == 0);
srcyuv_frames = tmp.st_size / (frame_width * frame_height * 1.5);
printf("Source YUV file %s with %llu frames\n", srcyuv_fn, srcyuv_frames);

Expand Down Expand Up @@ -3277,6 +3285,10 @@ static int calc_PSNR(double *psnr)
srcyuv_ptr = mmap(0, fourM, PROT_READ, MAP_SHARED, fileno(srcyuv_fp), i);
recyuv_ptr = mmap(0, fourM, PROT_READ, MAP_SHARED, fileno(recyuv_fp), i);
if ((srcyuv_ptr == MAP_FAILED) || (recyuv_ptr == MAP_FAILED)) {
if (srcyuv_ptr != MAP_FAILED)
munmap(srcyuv_ptr, fourM);
if (recyuv_ptr != MAP_FAILED)
munmap(recyuv_ptr, fourM);
printf("Failed to mmap YUV files\n");
return 1;
}
Expand Down
7 changes: 6 additions & 1 deletion encode/vp9enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,12 @@ main(int argc, char *argv[])
file_size = ftello(yuv_fp);
frame_size = picture_width * picture_height + ((picture_width * picture_height) >> 1) ;

if ((file_size < frame_size) || ((frame_size != 0) && (file_size % frame_size))) {
if (frame_size == 0) {
fclose(yuv_fp);
printf("Frame size is not correct\n");
return -1;
}
if ((file_size < frame_size) || (file_size % frame_size)) {
fclose(yuv_fp);
printf("The YUV file's size is not correct\n");
return -1;
Expand Down

0 comments on commit 715a03f

Please sign in to comment.