summaryrefslogtreecommitdiff
path: root/tools/tiny_ssim.c
diff options
context:
space:
mode:
authorsdeng <sdeng@google.com>2019-04-04 14:10:19 -0700
committerSai Deng <sdeng@google.com>2019-04-05 21:51:41 +0000
commit39ce1c0ab137ad53e9e3cc9c3a276f1be37b37fb (patch)
treea25745e2fdbab9bd72bc1568f23e3a77d6b23c1e /tools/tiny_ssim.c
parent65e5ba89b3c15c2fdbad35808bc91c1838754270 (diff)
downloadlibvpx-39ce1c0ab137ad53e9e3cc9c3a276f1be37b37fb.tar
libvpx-39ce1c0ab137ad53e9e3cc9c3a276f1be37b37fb.tar.gz
libvpx-39ce1c0ab137ad53e9e3cc9c3a276f1be37b37fb.tar.bz2
libvpx-39ce1c0ab137ad53e9e3cc9c3a276f1be37b37fb.zip
tiny_ssim: Fix an 'Uninitialized argument value' bug
found by clang-7.0.1 static analysis. BUG=webm:1616 Change-Id: I7fb318aa7d4c8dd0a96bb20c6f8706ca1a632696
Diffstat (limited to 'tools/tiny_ssim.c')
-rw-r--r--tools/tiny_ssim.c49
1 files changed, 23 insertions, 26 deletions
diff --git a/tools/tiny_ssim.c b/tools/tiny_ssim.c
index 2d945bb98..958a5d984 100644
--- a/tools/tiny_ssim.c
+++ b/tools/tiny_ssim.c
@@ -107,7 +107,6 @@ typedef struct input_file {
static int open_input_file(const char *file_name, input_file_t *input, int w,
int h, int bit_depth) {
char y4m_buf[4];
- size_t r1;
input->w = w;
input->h = h;
input->bit_depth = bit_depth;
@@ -115,31 +114,29 @@ static int open_input_file(const char *file_name, input_file_t *input, int w,
input->buf = NULL;
input->file = strcmp(file_name, "-") ? fopen(file_name, "rb") : stdin;
if (input->file == NULL) return -1;
- r1 = fread(y4m_buf, 1, 4, input->file);
- if (r1 == 4) {
- if (memcmp(y4m_buf, "YUV4", 4) == 0) input->type = Y4M;
- switch (input->type) {
- case Y4M:
- y4m_input_open(&input->y4m, input->file, y4m_buf, 4, 0);
- input->w = input->y4m.pic_w;
- input->h = input->y4m.pic_h;
- input->bit_depth = input->y4m.bit_depth;
- // Y4M alloc's its own buf. Init this to avoid problems if we never
- // read frames.
- memset(&input->img, 0, sizeof(input->img));
- break;
- case RAW_YUV:
- fseek(input->file, 0, SEEK_SET);
- input->w = w;
- input->h = h;
- // handle odd frame sizes
- input->frame_size = w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
- if (bit_depth > 8) {
- input->frame_size *= 2;
- }
- input->buf = malloc(input->frame_size);
- break;
- }
+ if (fread(y4m_buf, 1, 4, input->file) != 4) return -1;
+ if (memcmp(y4m_buf, "YUV4", 4) == 0) input->type = Y4M;
+ switch (input->type) {
+ case Y4M:
+ y4m_input_open(&input->y4m, input->file, y4m_buf, 4, 0);
+ input->w = input->y4m.pic_w;
+ input->h = input->y4m.pic_h;
+ input->bit_depth = input->y4m.bit_depth;
+ // Y4M alloc's its own buf. Init this to avoid problems if we never
+ // read frames.
+ memset(&input->img, 0, sizeof(input->img));
+ break;
+ case RAW_YUV:
+ fseek(input->file, 0, SEEK_SET);
+ input->w = w;
+ input->h = h;
+ // handle odd frame sizes
+ input->frame_size = w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
+ if (bit_depth > 8) {
+ input->frame_size *= 2;
+ }
+ input->buf = malloc(input->frame_size);
+ break;
}
return 0;
}