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 <[email protected]>
  • Loading branch information
Bossonor committed Dec 1, 2023
1 parent 505e7b3 commit 05ef2a3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion encode/avcenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ 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 ((file_size < frame_size) || (frame_size == 0) || (file_size % frame_size)) {
fclose(yuv_fp);
printf("The YUV file's size is not correct\n");
return -1;
Expand Down
7 changes: 6 additions & 1 deletion encode/hevcencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,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 +3278,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)
munmap(srcyuv_ptr, fourM);
if (recyuv_ptr)
munmap(recyuv_ptr, fourM);
printf("Failed to mmap YUV files\n");
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion encode/vp9enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ 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 ((file_size < frame_size) || (frame_size == 0) || (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 05ef2a3

Please sign in to comment.