tiny_ssim: mv read error checks closer to assignment
Quiets some spurious -Wmaybe-uninitialized warnings with gcc 14.1.0.
In function 'calc_plane_error16',
inlined from 'main' at ../tools/tiny_ssim.c:464:5:
../tools/tiny_ssim.c:37:12: warning: 'v[0]' may be used uninitialized
[-Wmaybe-uninitialized]
37 | if (orig == NULL || recon == NULL) {
| ^
In function 'calc_plane_error16',
inlined from 'main' at ../tools/tiny_ssim.c:462:5:
../tools/tiny_ssim.c:37:12: warning: 'u[0]' may be used uninitialized
[-Wmaybe-uninitialized]
37 | if (orig == NULL || recon == NULL) {
| ^
In function 'calc_plane_error',
inlined from 'main' at ../tools/tiny_ssim.c:461:5:
../tools/tiny_ssim.c:61:12: warning: 'y[0]' may be used uninitialized
[-Wmaybe-uninitialized]
61 | if (orig == NULL || recon == NULL) {
To reduce confusion, read_input_file() is changed to return an int as
previously it would only return (size_t)-1/0/1 (and now returns 0/1).
Change-Id: I2344048ecc2bd233891ffcef08002ee98d6d262a
diff --git a/tools/tiny_ssim.c b/tools/tiny_ssim.c
index 8fba814..e2ba0a9 100644
--- a/tools/tiny_ssim.c
+++ b/tools/tiny_ssim.c
@@ -150,12 +150,15 @@
}
}
-static size_t read_input_file(input_file_t *in, unsigned char **y,
- unsigned char **u, unsigned char **v, int bd) {
+// Returns 1 on success, 0 on failure due to a read error or eof (or format
+// error in the case of y4m).
+static int read_input_file(input_file_t *in, unsigned char **y,
+ unsigned char **u, unsigned char **v, int bd) {
size_t r1 = 0;
switch (in->type) {
case Y4M:
r1 = y4m_input_fetch_frame(&in->y4m, in->file, &in->img);
+ if (r1 == (size_t)-1) return 0;
*y = in->img.planes[0];
*u = in->img.planes[1];
*v = in->img.planes[2];
@@ -175,7 +178,7 @@
break;
}
- return r1;
+ return r1 != 0;
}
static void ssim_parms_8x8(const uint8_t *s, int sp, const uint8_t *r, int rp,
@@ -399,31 +402,37 @@
}
while (1) {
- size_t r1, r2;
+ int r1, r2;
unsigned char *y[2], *u[2], *v[2];
r1 = read_input_file(&in[0], &y[0], &u[0], &v[0], bit_depth);
-
- if (r1) {
- // Reading parts of file1.yuv that were not used in temporal layer.
- if (tl_skips_remaining > 0) {
- --tl_skips_remaining;
- continue;
+ if (r1 == 0) {
+ if (ferror(in[0].file)) {
+ fprintf(stderr, "Failed to read data from '%s'\n", argv[1]);
+ return_value = 1;
+ goto clean_up;
}
- // Use frame, but skip |tl_skip| after it.
- tl_skips_remaining = tl_skip;
- }
-
- r2 = read_input_file(&in[1], &y[1], &u[1], &v[1], bit_depth);
-
- if (r1 && r2 && r1 != r2) {
- fprintf(stderr, "Failed to read data: %s [%d/%d]\n", strerror(errno),
- (int)r1, (int)r2);
- return_value = 1;
- goto clean_up;
- } else if (r1 == 0 || r2 == 0) {
break;
}
+
+ // Reading parts of file1.yuv that were not used in temporal layer.
+ if (tl_skips_remaining > 0) {
+ --tl_skips_remaining;
+ continue;
+ }
+ // Use frame, but skip |tl_skip| after it.
+ tl_skips_remaining = tl_skip;
+
+ r2 = read_input_file(&in[1], &y[1], &u[1], &v[1], bit_depth);
+ if (r2 == 0) {
+ if (ferror(in[1].file)) {
+ fprintf(stderr, "Failed to read data from '%s'\n", argv[2]);
+ return_value = 1;
+ goto clean_up;
+ }
+ break;
+ }
+
#if CONFIG_VP9_HIGHBITDEPTH
#define psnr_and_ssim(ssim, psnr, buf0, buf1, w, h) \
do { \